select dropdown for belongs_to field

567 views
Skip to first unread message

skunkwerk

unread,
Jul 18, 2009, 1:59:02 PM7/18/09
to Ruby on Rails: Talk
Hi,
I have a 'person' model that belongs_to a 'group' model. I used
scaffolding to generate the form code for adding a new person, but I
want a select drop-down for selecting which group to assign a person
to. I looked at the rails form helpers guide, and tried a few
different things in the template, like:

<%= f.select :vendor, @vendor %>
but i'm getting errors...

what's the proper way to do this? is there any controller code
necessary?

thanks!

Virendra Negi

unread,
Jul 21, 2009, 2:08:34 PM7/21/09
to rubyonra...@googlegroups.com

here is it is
f.select(:group_id,Group.all,:prompt => true)
i think it should work
--
Posted via http://www.ruby-forum.com/.

Reply all
Reply to author
Forward
0 new messages