Ruby on rails Rails:为url传递多个参数以形成_?
这非常有效:Ruby on rails Rails:为url传递多个参数以形成_?,ruby-on-rails,Ruby On Rails,这非常有效: - form_for @user, :url => { :action => :create, :type => @type } do |f| ... 返回/users/(id)?type=type 但在另一个视图中,我需要将两个参数传递到URL字符串中,这不起作用: - form_for @user, :url => { :action => :update, :type => @type, :this => @currently_ed
- form_for @user, :url => { :action => :create, :type => @type } do |f| ...
返回/users/(id)?type=type
但在另一个视图中,我需要将两个参数传递到URL字符串中,这不起作用:
- form_for @user, :url => { :action => :update, :type => @type, :this => @currently_editing } do |f| ...
返回/users/(id)?这=当前正在编辑
我也试过:
- form_for @user, :url => { :action => :update, :params = params.merge({:this => @currently_editing, :type = @type})} do |f| ...
。。。没有运气(错误:只允许获取请求)
我希望它返回以下内容:/users/(id)?this=current\u editing&type=type
想法?为什么需要将它们传递到URL字符串中?为什么不将它们作为隐藏字段添加到表单中?几乎在所有情况下,您都应该通过POST传递变量。我认为您必须将所需的querystring属性移到:url选项之外,如下所示:
form_for @user, :url => { :action => :update }, :type => @type, :this => @currently_editing do |f|
我会使用隐藏字段,但这应该可以:
<% form_for @user, :url => user_path(@user.id, :type => @type, :this => @currently_editing), :method => :put do |f| -%>
user\u路径(@user.id,:type=>@type,:this=>@当前正在编辑),:method=>:put do | f |-%>
:method=>:put
在使用RESTful路由时触发更新操作。请尝试执行此操作
您可以通过这种方式传递多个参数
- form_for @user, :url => xxx_yyy_path(:param1 => value1, :params2 => value2, ......) do |f| ...
隐藏字段是否适用于不属于post模型一部分的参数?您仍然可以将隐藏字段添加到表单中,而不必使用表单_作为帮助工具。