从表单中的集合选择向控制器提交多个属性

时间:2017-10-10 01:02:04

标签: ruby-on-rails

我希望rails中的集合选择标记在提交表单时将所选项目的两个属性提交给控制器。基本上,我有一个县的列表,我想提交县和州作为参数。没有问题让它提交一个或另一个,但不是两个。我是否以错误的方式思考这个问题?这是我到目前为止所拥有的......

<%= form_tag(plans_path, method: 'get', action: 'screen2') do %>
    <%= text_field_tag :ZIP, "ZIP Code", id: "zipBlur"%>

    <%= collection_select(nil, :county, @counties.order('RES_RATIO DESC'), :COUNTY, :COUNTY_NAME, {:selected => "#{params[:county]}"}) %>

    <%= submit_tag 'Screen', :name=> nil %> 

<% end %>

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

使用:multiple => true

例如:

<%= collection_select(:ingredient, :supplier_ids, 
              Supplier.all(:order=>"name ASC"), 
              :id, :name, {:selected => @ingredient.supplier_ids, :include_blank => true}, {:multiple => true}) %>
相关问题