Ruby-on-rails Rails:使用参数重定向

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5433591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:46:56  来源:igfitidea点击:

Rails: redirect with params

ruby-on-railsruby-on-rails-3redirectroutingparams

提问by Andrew

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.

我看到一些例子说,如果你只是将它们添加到你的重定向哈希中,它们会与请求一起传递,但这在 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.

如果用户在 上items page 3,进行了一些更改并按下了 sumbit,则控制器操作会收到带有已更改记录 ID 的 post 请求,进行更改并重定向到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?

上面的代码不起作用,那么有人有什么例子吗?

回答by Harish Shetty

Try this:

尝试这个:

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