从Rails 2.3.6开始不推荐使用overwrite_params-接受的解决方法? [英] overwrite_params deprecated as of Rails 2.3.6 -- Accepted Workaround?
问题描述
因此,从Rails 2.3.6开始,似乎已弃用 overwrite_params
。有没有一种通常被认为是最佳实践的合适的解决方法?
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))
谢谢您的帮助。
推荐答案
我实际上只是在Railscast一集中看到了这一点: http://railscasts.com/episodes/240-search-sort- paginate-with-ajax
I actually just saw this mentioned in a Railscast episode: http://railscasts.com/episodes/240-search-sort-paginate-with-ajax
他基本上使用params.merge来建议您所说的话。请注意,您无需说出request.params,params就足够了。另外,如果您使用的是link_to,则可能不需要url_for。换句话说,如果您有:
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:
link_to title, url_for(params.merge(:page => 1))
然后可以说
link_to title, params.merge(:page => 1)
这篇关于从Rails 2.3.6开始不推荐使用overwrite_params-接受的解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!