以下是我的两个模型类
- class Patient < ActiveRecord::Base
- belongs_to :user,:dependent => :destroy
- has_many :enrollments,:dependent => :destroy
- has_many :clients,:through => :enrollments
- accepts_nested_attributes_for :user
- accepts_nested_attributes_for :enrollments
- attr_accessible :user_attributes,:enrollments_attributes,:insurance
- end
- class Enrollment < ActiveRecord::Base
- belongs_to :client
- belongs_to :patient
- attr_accessible :client_id,:patient_id,:active
- end
在我的患者表格中,我希望有一个多选框,可以将患者分配给客户.有没有办法可以做到这一点,所以我没有任何逻辑
控制器除外
- @patient = Patient.new(params)
- @patient.save
我试过这个:
- <%= patient_form.fields_for :enrollments do |enrollments_fields| %>
- <tr>
- <td class="label">
- <%= enrollments_fields.label :client_id %>:
- </td>
- <td class="input">
- <%= enrollments_fields.collection_select(:client_id,@clients,:id,:name,{},:multiple => true) %>
- </td>
- </tr>
- <% end %>
但它只保存了第一个客户端.如果我删除多个部分,它的功能,但我只能选择1个客户端!
select的html值是: