0
我有這樣的代碼多選擇在軌嵌套屬性4
class Department < ActiveRecord::Base
has_many :admin_permissions
accepts_nested_attributes_for :admin_permissions
end
查看:
= ep.fields_for :department, dept_object do |dept|
= dept.fields_for :admin_permissions, @user.admin_permissions.new(department: dept.object) do |ap|
= ap.collection_select :permission_type, AdminPermission.permission_types.map{ |dp| [dp.first, dp.first.humanize] }, :first, :second, {}, { :multiple => true, class: 'form-control' }
但在提交按鈕被按下後的參數,可以在PARAMS是這樣的:
"department_attributes"=>
{"company_id"=>"2",
"name"=>"",
"admin_permissions_attributes"=>{"0"=>{"permission_type"=>["", "human_resource"]}}},
而不是
"department_attributes"=>
{"company_id"=>"2",
"name"=>"",
"admin_permissions_attributes"=>{"0"=>{"permission_type"=>"hr"}, "1" => {"permission_type" => "manager"}}}
我怎樣才能實現這與多選擇?謝謝!
是否會創建單獨的對象? – user3620046
不,我想你必須自己在控制器中執行update_attribute調用。但我不確定這可以與你的符號一起工作。與嵌套屬性的關係是什麼類型?你確實想爲每個傳入的選擇創建一個新的,而不僅僅是像has_and_belongs_to_many關係那樣傳遞和關聯,對嗎? – talkingfox