Forms And Basic Associations Rails Lab
Objectives
Practice defining associations
Practice building forms in ERB when working with nested models
A Song Library
Song LibraryIn this lab, we're going to make a song library that helps record thoughts about various Songs. Our data model looks like this:
Artisthas a
nameattribute (String)has many
Songs
Songhas a
titleattribute (String)belongs to an
Artistbelongs to a
Genrehas many
Notes
Genrehas a
nameattribute (String)has many
songs
Notehas
contentattribute (String)belongs to a
Song
Instructions
The base models, controllers, and seed data have been provided for you.
You should create and migrate the database before starting to develop your solution.
Seeding the database provides many
Genres. You will add data aboutArtists,Notes, andSongs during the development of this application. TheArtistsControllerandSongsControllerhave been built out so that you can do this.
First, connect the models by using the ActiveRecord association commands.
Next, update the minimal app/views/songs/new.html.erb.
This view should have a form that provides:
A text input box that sets the
Song's title.A text input box for the
Artist.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.
This is a challenging lab because we want you to use Rails' powerful nested form builder view helpers. Here are some hints:
You might need to reference information on passing an
Arrayusingstrong_paramsIt's easy to get confused between getting an
Artistinstance from aSongand anArtist's name. To help make your form work easier, solve thespec/models/song_spec.rbfirst. You can run a single spec by invoking it with e.g.rspec spec/models/song_spec.rbMake use of the references below!
While we direct you to update
new.html.erb, you're going to need to make changes in multiple models and theSongsController.
References
Clone https://github.com/learn-co-curriculum/forms-and-basic-associations-rails-lab
Last updated