我试图从 URL 获取参数,然后使用该参数调用函数。但问题是参数有时包含 _
字符,该字符会被跳过并将错误的参数传递给函数。
假设我的网址是localhost:3000/deal/diamond_deal
。我得到的参数为
q= params[:promo]
但这样做时,q 将设置为 diamond deal
而不是 diamond_deal
。如何解决这个问题,有人可以帮忙吗?
谢谢
编辑:1. URl 的路由:match "/deal/:promo"=> "deal#index", :as => "deal"
2.Rails版本:Rails 3.1.10
最佳答案
接受的解决方案(在评论中)是使用 -
而不是 _
并将 -
替换为 _
Controller 。
关于ruby-on-rails - 错误率: How to retain underscore from URL parameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21428250/