路径助手插入加号而不是空格

时间:2014-04-06 12:41:11

标签: ruby-on-rails url ruby-on-rails-4

我想要一个带有

的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而不是空格?

1 个答案:

答案 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"

希望这有帮助!