Reputation: 17174
According to the specification about 25 characters in URL should be encoded:
http://en.wikipedia.org/wiki/Percent-encoding
It turns out Rails 3 encode only few characters ([]&?) and others are untouched (/).
Therefore when I use something like this:
test_param = "test/a?bc"
link_to "Test link", :test_param => test_param
the URL is broken (Route not found error). Thats because while question mark was percent-encoded the slash was not. And that breaks url.
Now I need to work with params including slashes. How to force proper url encoding for link_to method? Maybe to use explicit encoding (CGI.encode)? Is this a proper solution?
Upvotes: 0
Views: 1254
Reputation: 65467
I think it is much better to explicitly encode a string (the other option would be to override the link_to implementation, but that would be potentially really bad because other gems/Rails itself could be depending on it to behave as it is defined).
Also since the param that you have in your app can potentially contain forward slashes, it is better to be explicit about it so that after few months, you still know why you are explicitly encoding! (better code readability)
Upvotes: 1