Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove extra appended characters to a text stored in MySQL
    text
    copied!<p>I have an api controller that collects information from the api users. However, some user information when sent and stored in the MySQL database sometimes its appears with added underscores like this <code>"this is a test ________"</code> instead of <code>this is a test</code>. However when run through the browser it stores just fine.</p> <p>What could be the problem.</p> <p>Controller extract;</p> <pre><code>@message.message = CGI.unescape(params[:message]).strip </code></pre> <p>As a temporary fix, any ideas how i can strip away all the 6 underscores that are being added to the message either in storage or when it comes.</p> <pre><code>class Api::V1::Json::MessagesController &lt; ApplicationController before_filter :authenticate require 'uri' require 'cgi' def sms @message = Message.new #@message.to = decoded_to.gsub(/[^\d]/,"") @message.to = CGI.unescape(params[:to]).strip.gsub("+","").gsub(/\s+/, "") @message.from = CGI.unescape(params[:from]) @message.message = CGI.unescape(params[:message]).strip @message.user_id = current_user.id @message.status = 'Queued' if @message.save MessageWorker.perform_async(@message.id, [""], current_user.id) render json: {status: "Success"} else render json: {status: "Failed" } end end private def authenticate error!('Unauthorized. Invalid token.', 401) unless current_user end def current_user # find token. Check if valid. user_token = params[:token] token = ApiKey.where(:access_token =&gt; user_token).first if token @current_user = User.find(token.user_id) else false end end end </code></pre> <p>and the model is;</p> <pre><code>class Message &lt; ActiveRecord::Base attr_accessible :message, :phone, :status, :to, :from, :user_id attr_accessor :schedule validates :message, :presence =&gt; true validates :from, :presence =&gt; true validates :to, :presence =&gt; true validates :status, :presence =&gt; true validates_length_of :message, :maximum =&gt; 1600, :allow_blank =&gt; true validates_length_of :from, :maximum =&gt; 11, :allow_blank =&gt; false belongs_to :user </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload