我有一个应用程序,我正在对模型进行 collection_select。我需要能够从 SpecialEquipment 中选择多个 ID。
这是我的选择声明:
<%= f.collection_select(:special_equipment_id, SpecialEquipment.all, :id, :name, {}, {:multiple => true, :class => 'select'})%>
我正在使用 select2 gem 使 UI 更具吸引力,它允许我选择多个 id,但是当表单写入数据库时,它只写入第一个选择。
1.9.3p194 :004 > Call.last.special_equipment
Call Load (0.9ms) SELECT "calls".* FROM "calls" ORDER BY "calls"."id" DESC LIMIT 1
SpecialEquipment Load (0.3ms) SELECT "special_equipments".* FROM "special_equipments" WHERE "special_equipments"."id" = 1 LIMIT 1
=> #<SpecialEquipment id: 1, name: "O2", created_at: "2012-06-27 21:43:41", updated_at: "2012-06-27 21:43:41">
我究竟做错了什么?我的关联设置如下:
Call.rb belongs_to :special_equipment
Special_Equipment.rb has_many :calls