ruby on rails - Selecting belongs_to parents in a form? -
imagine have this:
class employer < activerecord::base has_many :employees end class employee < activerecord::base belongs_to :employer end
and want create new employee, , give form with drop downwards box, can select employer wish associate with. dropdown should list every employer in system. how can this?
thanks.
i think haven't understood association does. or haven't understood want.
if want display employers in view, have fetch them in corresponding controller action , save in instance variable. can access contents within view.
controller action:
@employers = employer.all ...
corresponding view:
<%= collection_select @employers %>
ruby-on-rails
No comments:
Post a Comment