Skip to Content
Learn
Associations II
Models I

Looking at the request/response cycle, we need four parts to the build the movie app: models, controllers, routes, and views.

Let’s begin by creating the models.

Instructions

1.

Generate a model named Movie.

2.

Generate another model named Actor.

3.

Generate a third model named Part.

4.

In app/models/movie.rb, inside the Movie class add the following methods:

has_many :parts has_many :actors, through: :parts
5.

In app/models/actor.rb, add the following methods:

has_many :parts has_many :movies, through: :parts
6.

In app/models/part.rb, add the following methods:

belongs_to :movie belongs_to :actor
Folder Icon

Sign up to start coding

Already have an account?