Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: redirect with params

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?

like image 587
Andrew Avatar asked Mar 25 '11 14:03

Andrew


1 Answers

Try this:

redirect_to(edit_multiple_items_path(:page =>2), :notice => 'items updated')
like image 158
Harish Shetty Avatar answered Nov 18 '22 19:11

Harish Shetty