如何在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: "client", action: "get_name", params: request.query_parameters and return
其他回答
从Rails 6开始,您可以简单地调用redirect_to,后跟希望重定向到的路径(如home_path),然后pass是键-值对的散列。
例子:
redirect_to home_path(name: 'Jason', needs: 'help with rails', help: true)
在此之后,您将能够从params散列中检索这些值。
ex
params[:名称]
检索字符串'Jason'
只需将它们附加到选项:
redirect_to controller: 'thing', action: 'edit', id: 3, something: 'else'
Would yield /thing/3/edit?其他的东西=
routes.rb
match 'controller_name/action_name' => 'controller_name#action_name', via: [:get, :post], :as => :abc
任何你想重定向参数的控制器如下所示:
redirect_to abc_path(@abc, id: @id), :notice => "message fine"
redirect_to new_user_path(:id => 1, :contact_id => 3, :name => 'suleman')
你要定你的路,取巴仑回来。
redirect_to controller: "client", action: "get_name", params: request.query_parameters and return