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: | | <p> | <%= f.label :last_name %><br /> | <%= f.text_field :last_name %> | </p> | | 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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2009-Feb-13 08:34 UTC
Re: another collection_select, HABTM, :multiple question
Sergio Ruiz wrote:> ,----[ worker ] > | class Worker < ActiveRecord::Base > | has_and_belongs_to_many :skillsets > | belongs_to :instructor > | end > ... > | <%= collection_select(:worker, :skillsets, Skillset.find(:all), :id, :title, {}, {:multiple => true}) %> > ... > + 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.Try collection_select(:worker, :skillset_ids, ... -- Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sergio Ruiz
2009-Feb-13 13:46 UTC
Re: another collection_select, HABTM, :multiple question
> 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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---