私はSezzionモデルを持っています:
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モデル:
attr_accessible :bio
has_many :sezzions, :through => :session_instructors
has_many :session_instructors, :dependent => :destroy
SessionInstructorモデル:
attr_accessible :instructor_id, :sezzion_id
belongs_to :sezzion
belongs_to :instructor
最後に、Userモデル:
has_many :sezzions
has_many :instructors
の複数選択オプションをSezzion持つネストされたフォームを使用してフォームを作成しようとしています。SessionInstructorInstructors
どうすれば次のことができますか:
- のネストされたフォーム
SessionInstructor - 複数選択オプションを使用して、選択したすべての を取得し
Instructorますinstructor_id session_id選択したインストラクターごとに作成/更新されたフィールドを渡す隠しフィールド
現在、次のコードがあります。
<%= 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 %>
どうもありがとう!