Rails中form_for中的附加参数

ber*_*ami 7 ruby-on-rails

是否可以在rails中的表单数据之外提交另一个参数?我的问题是我为不同的类渲染不同的表单并将它们发送到相同的create方法.我想发送带有表单的类(作为值不是哈希中的键).类似于:type参数(实际上不起作用)

<%= form_for(@an_object, :url => { :controller => :a_controller, :action => :create }, 
    :type => @an_object.class.to_s.underscore) do |f| %>
Run Code Online (Sandbox Code Playgroud)

帖子消息如下:

{"commit"=>"Create Class of an Object",
 "authenticity_token"=>"/iqu0A8/AocDT3HyjL5/+bKZiLkyr4FE71u/mc8Wx0Y=",
 "utf8"=>"✓",
 "class_of_an_object"=>{"name"=>"a name",
 "description"=>"a description"}}
Run Code Online (Sandbox Code Playgroud)

我会有一个"type" => "class_of_an_object",但直接在哈希中不在"class_of_an_object"哈希中.

fl0*_*00r 13

<%= form_for @an_object, 
             :url => { :controller => :a_controller, 
                       :action => :create, 
                       :type => @an_object.class.to_s.underscore } do |f| %>
Run Code Online (Sandbox Code Playgroud)

我更喜欢使用命名路线

<%= form_for @object, :url => object_path(@object, :type => "whtever"), :html => {:method => :post} do |f| %>
Run Code Online (Sandbox Code Playgroud)