Question: Ruby On Rails: How to create a drop down menu in one model that displays data that was created and stored in another model. There

Ruby On Rails: How to create a drop down menu in one model that displays data that was created and stored in another model.

There are two models. One called Course and one called Section. They were both created with the scaffold function as follows:

rails g scaffold course name department number:integer credit_Hours:decimal

Section was the same but with the values Semester, Number, Course, Room Number. Course being the one that I need to be a drop down menu to display the courses created by the course model.

I attempted to edit the in _form.html.erb of views of section and was able to get a drop down menu that displays the courses when attempted to create or edit a section, but when changes are saved the course is not saved with the section. How to, at a very basic level, get that drop down menu to display and record the courses for section?

I did this using the collection_select, but don't know if that is correct or what else I need to do to get it to store the course info in the new section.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!