Rails:使用参数重定向 [英] Rails: redirect with params

查看:80
本文介绍了Rails:使用参数重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过重定向传递一些参数的最佳方法是什么?

我看到了一些示例,这些示例说,如果您仅将它们添加到重定向哈希中,它们就会随着请求一起传递,但是在Rails 3中似乎不再起作用.

在我的示例中,我有一个多次修改"页面,该页面使用户可以一次更改多个项目的类别.由于他们浏览的商品太多,因此此表格是分页的.

如果用户在items page 3上,进行了一些更改并按sumbit,则控制器操作将收到带有已更改记录ID的发布请求,进行更改,然后重定向到edit_many_items_path. /p>

因此,该重定向如下所示:

redirect_to edit_multiple_items_path, :notice => 'items updated'

...但是我想要它做的事情是这样的:

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

上面的代码不起作用,所以有人能举个例子吗?

解决方案

尝试一下:

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

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?

解决方案

Try this:

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

这篇关于Rails:使用参数重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆