Forum: Ruby on Rails Url encode

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Alex (Guest)
on 2006-03-20 21:08
Can someone tell me how to encode a string to a url in Rails.
I've got basic code as below, but it only adds dashes in place of spaces
and doesn't escape html.
@page.url =[ ]/, '-')
Justin B. (Guest)
on 2006-03-20 21:23
(Received via mailing list)
@page.url = CGI::escape(

Will do URL encoding for you. To decode, use CGI::unescape().

More info is available by checking out the CGI class on the ruby-docs
This topic is locked and can not be replied to.