Below are two of my model classes
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, :patient_id, :active end
In my patient form, I would like to have a box with several choices where the patient can be assigned to clients. Is there any way to do this, so I don't need to have any logic in the controller except
@patient = Patient.new(params) @patient.save
I tried this:
<%= 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 %>
But he only saves the first customer. If I remove several parts, it will work, but I can only choose one client!
Html value to select:
source share