Ruby on rails: I need to render a View with data from two unrelated Models -
i trying create student view student details. in same view, need add collection_select populated values model hobbies (which separated, unrelated model)
now question how access hobbies model in student/id/new view?
can use fields_for this. if yes, how?
all models , controller instance variables accessible in views. do:
# in view <%= f.collection_select :hobbie_ids, hobbie.all, :id, :name, {}, multiple: true %> or do:
# in controller @hobbies = hobbie.all # in view <%= f.collection_select :hobbie_ids, @hobbies, :id, :name, {}, multiple: true %> the code above written in assumption have has_and_belongs_to_many :hobbies relationship.
Comments
Post a Comment