在 rails redirect_to 中传递参数 [英] Passing parameters in rails redirect_to

查看:36
本文介绍了在 rails redirect_to 中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在rails中的redirect_to中传递参数?我知道我们可以使用这个传递 id:

How do we pass parameters in redirect_to in rails? I know we can pass id using this:

redirect_to :action => action_name,:id => 3

如果我想传递额外的参数,比如一些表单数据,如何实现?

If I want to pass additional parameters like some form data how to achieve it?

对于 Ruby 2 语法,您必须将上面的代码段更新为:

For Ruby 2 syntax you have to update the snippet above to:

redirect_to action: action_name, id: 3

推荐答案

只需将它们附加到选项:

Just append them to the options:

redirect_to controller: 'thing', action: 'edit', id: 3, something: 'else'

会产生 /thing/3/edit?something=else

这篇关于在 rails redirect_to 中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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