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.



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.


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


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.


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.


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

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?