4
我试图保存多个选定的值形成一个由rails helper select生成的多选字段。选择:multiple => true不保存值
<div class="form-group">
<%= f.label :available_type, "Available in category" %><br>
<%= f.select :available_type, options_for_select(Setting.subscription_type, @terminal.available_type), { }, { class: "form-control", :multiple => true, :size => 5 } %>
</div>
这使得这样的(所选择的值是从先前的尝试没有 “:多个=> true” 属性完美的作品):
<select class="form-control" id="terminal_available_type" multiple="multiple" name="terminal[available_type][]" size="5">
<option value="Postpaid">Postpaid</option>
<option value="MBB">MBB</option>
<option selected="selected" value="Prepaid">Prepaid</option>
</select>
任何帮助是赞赏。 :)
编辑: 我试图把serialize :available_type
在我的终端型号,dident改变任何东西。 : -/
编辑2: 我注意到,多选字段不标记选项时,我标记它们。如果我添加manualy选定的属性我得到这些参数应用:
{"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"RrwWlKk8XlGeC+dTu/w6oSM68e9LcbUFJWTI+eRS9mI=", "terminal"=>{"inndate"=>"2015-01-13", "outdate"=>"", "brand_id"=>"2", "name"=>"iPhone 5c", "available_type"=>["", "MBB", "Prepaid"], "product_number"=>"3r2342", "ean_code"=>"", "navision_nb"=>"324234", "cost_price_map"=>"3200.0", "manual_price"=>"", "sales_info"=>"Just sell!"}, "commit"=>"Submit", "action"=>"update", "controller"=>"terminals", "id"=>"2"}
的available_type领域具有使用Rails 4.0.2的值"available_type"=>["", "MBB", "Prepaid"]
林,这里是我的强烈参数应用:
# Never trust parameters from the scary internet, only allow the white list through.
def terminal_params
params.require(:terminal).permit(:inndate, :outdate, :brand_id, :name, :product_number, :navision_nb, :cost_price_map, :manual_price, :sales_info, :available_type)
end
你可以发布你的控制器中收到的参数吗? –
为问题添加参数。我还注意到,如果选项未被手动标记为“已选”,则available_type参数不会被sendt获取。这是正常的吗? –
任何验证或回调?您使用的是哪种版本的导轨? –