Rails: redirect with params

*爱你&永不变心* 提交于 2019-12-03 10:34:26

问题


What's the best way to pass some params along with a redirect?

I saw examples that said if you just add them to your redirect hash they would pass along with the request, but that doesn't seem to work anymore in Rails 3.

In my example I have an 'edit multiple' page that lets a user change the category on multiple items at once. Because they're browsing so many items this form is paginated.

If a user is on items page 3, makes some changes and presses sumbit, then the controller action receives a post request with the ids of the records that were changed, makes the changes, and redirects to the edit_many_items_path.

So, that redirect looks like this:

redirect_to edit_multiple_items_path, :notice => 'items updated'

... but what I'd like it to do is something like:

redirect_to edit_multiple_items_path, :notice => 'items updated', :page => ##

The above code doesn't work, so does anyone have an example of what would?


回答1:


Try this:

redirect_to(edit_multiple_items_path(:page =>2), :notice => 'items updated')


来源:https://stackoverflow.com/questions/5433591/rails-redirect-with-params

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