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

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

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

编辑:

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

redirect_to action: action_name, id: 3

当前回答

可以使用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

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

redirect_to act_house_path (request.parameters)

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| %>

如果您正在使用RESTful资源,您可以执行以下操作:

redirect_to action_name_resource_path(resource_object, param_1: 'value_1', param_2: 'value_2')

or
#You can also use the object_id instead of the object
redirect_to action_name_resource_path(resource_object_id, param_1: 'value_1', param_2: 'value_2')

or
#if its a collection action like index, you can omit the id as follows
redirect_to action_name_resource_path(param_1: 'value_1', param_2: 'value_2')

#An example with nested resource is as follows:
redirect_to edit_user_project_path(@user, @project, param_1: 'value_1', param_2: 'value_2')