- Populate select options based on association options.
- Assign a FK based on a select box value directly through mass assignment. (post[category_id])
- Define a belongs_to association writer.
- Build a form field that will delegate to a belongs_to association writer. (post#category_name=) through controller mass assignment.
- Define a has_many association writer.
- Build a form field that will delegate to a has_many association writer. (owner#pet_names=) through controller mass assignment.
In this lab, we're going to make a song library. Our data model looks like this:
- Artist
- artists have a name (string)
- artists have many Songs
- Song
- songs have a title (string)
- songs belong to an Artist
- songs belong to a Genre
- Genre
- genres have a name (string)
- genres have many songs
- Notes
- notes have content (string)
- notes belong to a Song
The base models, controllers, and seed data have been provided for you. The associations have not been wired up.
- The basic models and such have been made for you.
- Write
app/views/songs/new.html.erb
. This form should have:
- A text input box that sets the song's name.
- A text input box for the artist, which autocompletes with existing Artist names.
- A selection box for genre. Users should be able to pick amongst existing genres only.
- Several text input boxes to add notes to the song. These should have the ids
song_note_contents_1
,song_note_contents_2
, and so on for the specs to pass.
There are feature tests!