Rails: How to escape ampersand in URL formation -
i have link_to helper following:
<%= link_to "example & text", url_for(:controller =>'example', :title=>"example & text") %> it frames url http://localhost:3000/example?title=example&:text
in sample controller calls index method params[:title] returns value example&:text.
i want have value "example & text". have tried cgi::escape() , cgi::escapehtml() without luck.
the url needs escaped using cgi.escape:
link_to "example & text", :controller => "example", :title => cgi.escape("example & text") this should generate like:
<a href="/example?title=example+%26+text">example & text</a> then, wherever you're wanting use this, can unescape again normal:
cgi.unescape params[:title] # => "example & text"
Comments
Post a Comment