Notes posted by garg
RSS feed
Belongs_to, Has_many association
I have a belongs_to, has_many association between manufacturer and modelname. (manufacturer has many modelnames).
In the new modelname page, I have a drop down menu that lists all the manufacturers, so I choose eg Dell, and then in modelname.name field I enter inspiron or what ever. To create that drop down I used:
<%= f.select(:manufacturer_id, Manufacturer.find(:all).collect {|u| [u.name, u.id]}, :prompt => 'Select') %>
The reason that works was explained by fcheung and rsl on #rubyonrails. Thanks:
the form builder basically calls the method whose docs you have read, inserting the appropriate first argument
The object is referenced internally when you call f.whatever. in any of those tags, the object is omitted when used on a form block variable