Skip to Content
Learn
Associations II
Movies I

Nice work! Let’s review what we did:

  1. We added columns to the movies table and actors table
  2. We used the t.belongs_to methods in the parts table to add foreign keys, setting up the many-to-many relationship.
  3. Finally we ran the migrations to update the database, and seeded the database with the data in db/seeds.rb.

Instructions

1.

Now that the models are set up, let’s move on to the rest of the request/response cycle and create the routes, controllers, and views.

Generate a controller named Movies.

2.

In the routes file, create a new route that maps the URL /movies to the Movies controller’s index action.

3.

Then in the Movies controller, add the index action to display a list of all movies. To do this, fetch all movies from the database and store them in variable @movies.

4.

In app/views/movies/index.html.erb inside <div class="main"> iterate through each movie in @movies and display the image, title, and release year.

5.

Run the local server and visit http://localhost:8000/movies in the browser.

Folder Icon

Sign up to start coding

Already have an account?