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&amp:text

in sample controller calls index method params[:title] returns value example&amp: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

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -