@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/
On 3/20/06, Alex <maccman@gmail.com> wrote:> 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(/[ ]/, ''-'')
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>