# Another collection\_select, HABTM, :multiple question

**URL:** <https://www.ruby-forum.com/t/another-collection-select-habtm-multiple-question/160225>\
**Category:** Rails\
**Created:** [February 13, 2009, 7:13am UTC](https://www.ruby-forum.com/t/another-collection-select-habtm-multiple-question/160225 "2009-02-13T07:13:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [February 13, 2009, 7:13am UTC](https://www.ruby-forum.com/t/another-collection-select-habtm-multiple-question/160225/1 "2009-02-13T07:13:32Z")

</div>

i am currently working on a project and having a really tough time  
getting a collection\_select to work properly. this is using a multiple  
selection.

this is part of a HABTM relationship, and it appears that i have  
everything set up correctly… but there is just something not working  
…

the models i am working with are Worker and Skillset

they look like this:

,----[worker]  
| class Worker \< ActiveRecord::Base  
| has\_and\_belongs\_to\_many :skillsets  
| belongs\_to :instructor  
| end  
`----

,----[skillset]  
| class Skillset \< ActiveRecord::Base  
| belongs\_to :pathway  
| has\_many :skills  
| has\_and\_belongs\_to\_many :workers  
| end  
`----

what i am trying to do is pass a Worker to a form, and populate that  
form with the methods of the object. the form looks like this:

,----[form]  
| \<% form\_for :worker, @worker, :url =\> {:action =\> ‘update\_worker’, :worker\_id =\> @worker.id} do |f| -%\>  
|  
| with normal form things that look like this:  
|  
|

| \<%= f.label :last\_name %\>  
  
| \<%= f.text\_field :last\_name %\>  
|

  
|  
| with a collection\_select that looks like this:  
|  
| \<%= collection\_select(:worker, :skillsets, Skillset.find(:all), :id, :title, {}, {:multiple =\> true}) %\>  
|  
|  
| \<%= f.submit “Update” %\>  
| \<% end -%\>  
`----

what i am THINKING should happen is that:

- since the form hauls in a worker, i should be able to load up the  
collection box with all the skillsets and have the skillset that  
belong to the worker selected.

what does happen:

- all other fields behave as they should. this is a good thing.
- when the select box is rendered, it it shows all the skillsets  
correctly, but, the correct ones, the ones that are part of the  
Worker model are not selected. nothing is selected.

i have tried all sorts of permutations of this, and i am sure i am  
really close, but i just need a nudge in the right direction. thanks!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [February 13, 2009, 9:35am UTC](https://www.ruby-forum.com/t/another-collection-select-habtm-multiple-question/160225/2 "2009-02-13T09:35:42Z")

</div>

Sergio R. wrote:

> Worker model are not selected. nothing is selected.  
> Try

collection\_select(:worker, :skillset\_ids, …

–  
Rails Wheels - Find Plugins, List & Sell Plugins -  
[http://railswheels.com](http://railswheels.com)

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [February 13, 2009, 2:46pm UTC](https://www.ruby-forum.com/t/another-collection-select-habtm-multiple-question/160225/3 "2009-02-13T14:46:56Z")

</div>

> collection\_select(:worker, :skillset\_ids, …

holy mac!

this worked spot on…

i read and reread the documentation a million times, and didn’t get  
that…

thanks so much!
