如何在redirect_to中传递参数? 我知道我们可以用这个传递id:
redirect_to :action => action_name,:id => 3
如果我想传递额外的参数,比如一些表单数据,如何实现呢?
编辑:
对于Ruby 2语法,你必须将上面的代码片段更新为:
redirect_to action: action_name, id: 3
如何在redirect_to中传递参数? 我知道我们可以用这个传递id:
redirect_to :action => action_name,:id => 3
如果我想传递额外的参数,比如一些表单数据,如何实现呢?
编辑:
对于Ruby 2语法,你必须将上面的代码片段更新为:
redirect_to action: action_name, id: 3
当前回答
只需将它们附加到选项:
redirect_to controller: 'thing', action: 'edit', id: 3, something: 'else'
Would yield /thing/3/edit?其他的东西=
其他回答
redirect_to :controller => "controller_name", :action => "action_name", :id => x.id
如果您有一些表单数据,例如发送到home#action,现在您希望在保留参数的同时将它们重定向到house#act,您可以这样做
redirect_to act_house_path (request.parameters)
从Rails 6开始,您可以简单地调用redirect_to,后跟希望重定向到的路径(如home_path),然后pass是键-值对的散列。
例子:
redirect_to home_path(name: 'Jason', needs: 'help with rails', help: true)
在此之后,您将能够从params散列中检索这些值。
ex
params[:名称]
检索字符串'Jason'
可以使用flash参数将任意对象传递给模板。
redirect_to :back, flash: {new_solution_errors: solution.errors}
然后通过散列在模板中访问它们。
<% flash[:new_solution_errors].each do |err| %>
你要定你的路,取巴仑回来。
redirect_to controller: "client", action: "get_name", params: request.query_parameters and return