views:

691

answers:

1

Is there an equivalent to PHP's urlencode in Ruby on Rails 2.3.5? I googled it but all the answers seem to date back to before 2006 and seems dates. This is what I found. It seems a bit abnormal to call CGI::escape in a view.

Is there an equivalent helper function?

Thanks!

+4  A: 

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.

Mike Trpcic
Nope. PHP's urlencode (see http://php.net/urlencode) does things like " " -> "%20".
Matchu
Ahh, my apologies. Please see my edited answer.
Mike Trpcic
Ahh! Haven't had the chance to use that helper yet! SO won't let me switch votes because it doesn't seem to think your answer is edited; I'll check back in a few minutes to see if that changes.
Matchu
thank you guys!
yuval