url encode equivalent in ruby on rails url encode equivalent in ruby on rails ruby ruby

url encode equivalent in ruby on rails


I believe the u helper method is what you're looking for:

<%=u "URL ENCODE <p>ME</p>" %>

I can't seem to find the documentation for that method, but if I find it in the near future I'll be sure to put a link in here.

Edit: You can find the documentation for this method here.


If you want to do it without ERB, you can use the following:

Rack::Utils.escape('http://example.com')#=> "http%3A%2F%2Fexample.com"


This worked better for me than the Rack::Utils.escape:

URI::escape('http://example.com/?param=Hello World')

Because it replaced the spaces with %20 instead of +