# Multi Select with fields\_for

**URL:** <https://www.ruby-forum.com/t/multi-select-with-fields-for/177920>\
**Category:** Rails\
**Created:** [October 26, 2009, 7:04pm UTC](https://www.ruby-forum.com/t/multi-select-with-fields-for/177920 "2009-10-26T19:04:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![acgreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3bc359/32.png) [@acgreen](https://www.ruby-forum.com/u/acgreen)\
**Post date:** [October 26, 2009, 7:04pm UTC](https://www.ruby-forum.com/t/multi-select-with-fields-for/177920/1 "2009-10-26T19:04:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![acgreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3bc359/32.png) [@acgreen](https://www.ruby-forum.com/u/acgreen)\
**Post date:** [October 26, 2009, 7:43pm UTC](https://www.ruby-forum.com/t/multi-select-with-fields-for/177920/2 "2009-10-26T19:43:40Z")

</div>

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](http://www.marnen.org)  
removed\_email\_address@domain.invalid

> TIA
