overwrite_params deprecated as of Rails 2.3.6 — Accepted Workaround?

你说的曾经没有我的故事 提交于 2019-12-06 06:51:40

问题


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.


回答1:


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:

link_to title, url_for(params.merge(:page => 1))

then it might suffice to say

link_to title, params.merge(:page => 1)


来源:https://stackoverflow.com/questions/3267781/overwrite-params-deprecated-as-of-rails-2-3-6-accepted-workaround

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!