Creating Related Resources Lab

Setup

For today’s lab, we are going to continue building the Record Collection.

Objective: Use a form to create songs for each album

  1. Open your Record Collection project.
    • If you have been absent, follow these steps:
      • Fork and Clone it from this Starter Repository.
      • Create the database by running update-database from the Package Manager Console.
      • Open the database in pgAdmin, and create some records by running the following script (feel free to update the albums and artists to your favorites!).
          INSERT INTO albums (title, artist, release_date)
          VALUES
          ('Stop Making Sense', 'Talking Heads', '1984-06-24'),
          ('Banana Winds', 'Jimmy Buffet', '1996-12-06')
        
      • Build the project, and let an instructor know if you receive any errors.

Write Tests for Songs#New and Songs#Create Action

With a Partner

  1. Create some user stories to describe how a song will be created in your application
  2. Outline (pseudo-code) the tests that will drive the implementation of the user stories
  3. Individually, create the tests that you outlined with your partner.
  4. When finished, check in with an instructor before moving on.

Implement the Songs#New and Songs#Create Actions and View

With a Partner

  1. Create the New action and view.
  2. Create the Create action that will add a new song to an album.
  3. When finished check in with an instructor!

🌶️Update the application to include Artist as a Resource🌶️

To better represent our Record Collection, it would be best for an artist to be it’s own resource. So, we want to update our application to have an Artist model, and update our database to include an Artist table. An artist will have many records, and a record could have many artists.

For a refresher on this type of relationship, review the Many to Many Lesson from Mod2.

Update the Database

  1. Update your Models to include Artist
    • review the existing models - they may need to be updated for this change!
  2. Create a migration to add the artists table and artistrecords table to your application
    • Check in with an instructor before moving on.
  3. When approved by an instructor, update your database by running the migration.

Update the Web Application

  1. List the RESTful routes for the Artist resource.
    • Include the path, method, and controller#action for each.
    • Check in with an instructor before moving on.
  2. When your routes have been approved, create the controller actions and views for:
    • Index
    • New
    • Create

Lesson Search Results

Showing top 10 results