[Rails] HELP - Save drop down list using "collection_select"

ryan heath
Sun, 16 Jul 2006 03:53:01 -0000

Each post has a single category, which I''m filling a drop down list by
using this:

#view
Category <br
/>
<%= collection_select(:id, :type_id, Type.find(:all), :id, :category) %>


In my Post model I have a field called "type_id" which is to be filled
by the id in the Type table upon selection.  When I click "create" on
my
Post, I want it to get whichever category is selected, and save it in
the "type_id" field.  I don''t know if I''m going
about this wrong or not.
I''ve never done this before, and can''t get it to work.  I get
the drop
down list to populate from the Type table, but that''s it.

Also, what about editing?  When I edit, will it load the selected type?

Thanks a lot for any thoughts on this!

--
Posted via http://www.ruby-forum.com/.