Another collection_select, HABTM, :multiple question

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!

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

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!