Skip to content Skip to sidebar Skip to footer

Encodeuricomponent Decoding It In Rails

Normally rails magically decodes all params. Now I got a javascript which does params='value='+encodeURIComponent('ab#cd'); and then calls http://server/controller?value=ab%23cd. I

Solution 1:

Rails "automagically" handles parameters with the following logic.

If the request is GET it will decode anything in the query string:

GET http://server/controller?value=ab%23cd
  On the server this will generate params['value'] as ab#cd

If the request is a POST with a query string it will not decode it:

POST http://server/controller?value=ab%23cd
  On the server this will generate params['value'] as ab%23cd

If the request is a POST with data parameters, it will decode it:

POST http://server/controller
  data: value=ab%23cd
  On the server this will generate params['value'] as ab#cd

I suspect that you're seeing this issue because you're including a query string with a POST request instead of a GET request and so Rails isn't decoding the query string.

Post a Comment for "Encodeuricomponent Decoding It In Rails"