Let's take a look at how our Sinatra application and views will need to change to include our new
Artist class along with its many-to-many functionality with the
We will need the following routes:
Note that these routes are exactly the same as the basic routes for the
Album class. There is no need to do any nesting of routes between
Artist because this is not a dependent one-to-many relationship.
We'll also need the following new views:
Note that we could also put any edit and delete forms on the artist.erb page, which means we wouldn't need to have an edit_artist.erb page.
It may also be useful to have a new root route with an index.erb that shows a list of all albums and artists.
The code to add this functionality to our record store application is pretty much identical to the routes and views we've added so far with albums so we won't cover it in detail. At this point, this kind of repetition may be feeling a bit CRUDdy. Fortunately, Rails will vastly simplify our code for routing in the next course section.
Lesson 17 of 29
Last updated August 7, 2022