我想要一个带有
的link_to<%= link_to "My Link", search_path(par: "My Link") %>
但这会呈现为
<a href="/search?par=My+Link">My Link</a>
而不是
<a href="/search?par=My Link">My Link</a>
有没有办法强制它行为正常,而不是手动插入%20
而不是空格?
答案 0 :(得分:0)
试试这个
require 'cgi'
CGI.unescape "/search?par=My+Link"
示例:
1.9.3p448 :006 > CGI.unescape "/search?par=My+Link"
=> "/search?par=My Link"
1.9.3p448 :007 > CGI.unescape "/search?par=My%20Link"
=> "/search?par=My Link"
希望这有帮助!