Forum: Ruby on Rails Url encode

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Baf018e2cc4616e4776d323215c7136c?d=identicon&s=25 Alex (Guest)
on 2006-03-20 20: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 = @page.name.to_s.gsub(/[ ]/, '-')
573b9499030e1ccb867ef80f0ff1ac49?d=identicon&s=25 Justin Bailey (Guest)
on 2006-03-20 20:23
(Received via mailing list)
@page.url = CGI::escape(@page.name)

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
site:

http://www.ruby-doc.org/core/
This topic is locked and can not be replied to.