I have a Sezzion
model:
attr_accessible :description
has_many :session_instructors, :dependent => :destroy
has_many :instructors, :through => :session_instructors
accepts_nested_attributes_for :session_instructors
accepts_nested_attributes_for :instructors
Instructor
model:
attr_accessible :bio
has_many :sezzions, :through => :session_instructors
has_many :session_instructors, :dependent => :destroy
SessionInstructor
model:
attr_accessible :instructor_id, :sezzion_id
belongs_to :sezzion
belongs_to :instructor
Lastly, User
model:
has_many :sezzions
has_many :instructors
I'm trying to create a form for Sezzion
with nested form for SessionInstructor
which has multiple select option for Instructors
.
How can I do the following:
- nested form for
SessionInstructor
- use multiple select option to get all the selected
Instructor
'sinstructor_id
- hidden field to pass in the created/updated
session_id
with each select instructor
I have the following code as of now:
<%= form_for(@sezzion) do |f| %>
<%= f.label :description %>
<%= f.text_area :description %>
<%= f.label :instructors %>
<%= fields_for :session_instructors do |f| %>
<select multiple>
<% current_user.instructors.each do |instructor| %>
<option><%= instructor.name %></option>
<% end %>
</select>
<% end %>
<%= f.submit %>
<% end %>
Thank you so much!