I’m trying to get a multi select box working with fields_for but am
having a
few problems.
My view has …
<% form_for(@teacher) do |f| %>
<%= f.label :surname %>
<%= f.text_field :surname %>
<% f.fields_for :qualifications do |qual_form| %>
Qualifications: <%= qual_form.select( :id, @qualifications) %>
<% end %>
<%= f.submit %>
<% end %>
Which produces (for the fields_for) …
Licence
NPLQ
Teacher's Level One
Teacher's Level Two
Teacher's Rescue Test
and on submission I have …
“teacher”=>{“qualifications_attributes”=>{“0”=>{“id”=>“2”}},
“surname”=>""}}
but what I think I really want is a multi select box with the submitted
data
looking something like …
“teacher”=>{“qualifications_attributes”=>{“id”=>[“2”,“3”,“4”]}},
“surname”=>""}}
Could somebody putme out of my misery, please?
TIA
Anthony G. wrote:
I’m trying to get a multi select box working with fields_for but am
having a
few problems.
My view has …
<% form_for(@teacher) do |f| %>
<%= f.label :surname %>
<%= f.text_field :surname %>
<% f.fields_for :qualifications do |qual_form| %>
Qualifications: <%= qual_form.select( :id, @qualifications) %>
<% end %>
<%= f.submit %>
<% end %>
Which produces (for the fields_for) …
Licence
NPLQ
Teacher's Level One
Teacher's Level Two
Teacher's Rescue Test
[…]
but what I think I really want is a multi select box with the submitted
data
looking something like …
“teacher”=>{“qualifications_attributes”=>{“id”=>[“2”,“3”,“4”]}},
“surname”=>“”}}
Could somebody putme out of my misery, please?
Do you know how to make a multiple select in HTML? You just use . So in Rails, you’d put :multiple => true in the
html_options for your select helper. Simple.
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
TIA