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

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

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

编辑:

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

redirect_to action: action_name, id: 3

当前回答

如果您有一些表单数据,例如发送到home#action,现在您希望在保留参数的同时将它们重定向到house#act,您可以这样做

redirect_to act_house_path (request.parameters)

其他回答

你要定你的路,取巴仑回来。

redirect_to controller: "client", action: "get_name", params: request.query_parameters and return
redirect_to :controller => "controller_name", :action => "action_name", :id => x.id

可以使用flash参数将任意对象传递给模板。

 redirect_to :back, flash: {new_solution_errors: solution.errors}

然后通过散列在模板中访问它们。

<% flash[:new_solution_errors].each do |err| %>
redirect_to new_user_path(:id => 1, :contact_id => 3, :name => 'suleman')

如果您有一些表单数据,例如发送到home#action,现在您希望在保留参数的同时将它们重定向到house#act,您可以这样做

redirect_to act_house_path (request.parameters)