从 Rails 2.3.6 开始不推荐使用 overwrite_params —— 接受的解决方法吗?
因此,从 Rails 2.3.6 开始,overwrite_params
似乎已被弃用。是否存在被普遍接受为最佳实践的合适解决方法?
例如,我曾经能够执行以下操作(我认为这非常有用):
url_for(:overwrite_params => {:page => 1})
我在网上看到了以下提到的解决方案...这是新的方法吗?
url_for(request.params.merge(:page => 1))
感谢您的帮助。
So, it looks like overwrite_params
is deprecated as of Rails 2.3.6. Is there a suitable workaround that is generally accepted as best-practice?
For example, I used to to be able to do the following (which I thought was quite useful):
url_for(:overwrite_params => {:page => 1})
I've seen the following solution mentioned online ... is this the new way to do it?
url_for(request.params.merge(:page => 1))
Thanks for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,我刚刚在 Railscast 剧集中看到了这一点:http://railscasts。 com/episodes/240-search-sort-paginate-with-ajax
他基本上建议你所说的,使用 params.merge。请注意,您不需要说 request.params,params 就足够了。另外,如果您使用 link_to,那么您可能不需要 url_for。换句话说,如果你有:
那么就可以说
I actually just saw this mentioned in a Railscast episode: http://railscasts.com/episodes/240-search-sort-paginate-with-ajax
He suggests basically what you said, using params.merge. Note that you don't need to say request.params, params is sufficient. Also if you're using link_to, then you may not need url_for. In other words, if you have:
then it might suffice to say