Reputation: 1489
I made an ajax request to rails. The URL is:
/learners/-638284588?is_combined_page=true&[email protected]&type=ld"
In the log, I see these entries:
Started GET "/learners/-638284588?is_combined_page=true& [email protected]&type=lcd" for 127.0.0.1 at Fri Feb 23 09:31:56 -0500 2018
Processing by Extranet::LearnersController#show as HTML
Parameters: {"type"=>"ld", "email"=>"test0221k [email protected]", "is_combined_page"=>"true", "id"=>"-638284588"}
[WARNING] Audit logging has been enabled for Account
parameter ----------------> {"type"=>"lcd", "email"=>"test0221k [email protected]", "controller"=>"extranet/learners", "is_combined_page"=>"true", "action"=>"show", "id"=>"-638284588"} test0221k [email protected]
In the URL, the email
parameter appears as:
email="[email protected]"
which has a +
sign. But when I read the parameter from params[:email]
, it is printed as:
"email"=>"test0221k [email protected]"
in which the +
is replaced by a space.
Why does rails overwrite +
with a space?
How can I avoid this "test0221k [email protected]"
and get "[email protected]"
?
Upvotes: 0
Views: 259
Reputation: 3348
This is defined by the URL specification. Rails is just confirming to that spec.
Parameters need to be encoded before putting them in the URL. The easy way to do this is to call encodeURIComponent()
in your JavaScript.
Forms do this encoding for you automatically.
Upvotes: 6