5. Movies II, Step 2: "retrieve all actors..."


I know that this step tells me to retrieve all actors related to the movie, but I can't find a way to relate both models (is it technically right? relating models?) in order to list all instances of one class (actor) that relate to one instance of another (movie). Is this way of thinking even correct?

So far my code looks like this:

def show
@movie = Movie.find(params[:id])
@actors = @movie.actor

this gives me the error "undefined method `actor' for #"

Everythigns i've tried returned me an error please help movie II 5 step 2

Ok, so I kept searching and came to the solution, which was pretty close to what I had.

This worked for me:

def show
@movie = Movie.find(params[:id])
@actors = @movie.actors

As the said page says, this is a collection of joined models.


Why ".actors" is become a method for instance variable "@movies"?

@actors = @movie.actors

after "."(dot) there is always a method. Do I understand it right?

EDIT: I understood after two weeks and few more courses.


A post was split to a new topic: The code still does not work. any idea why?


This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.