5. Movies II - Controller in many-to-many association


#1

the codeacademy let me proceed to the next step but in the browser it shows error in @actor line.
I know that that line is not correct but I really do not know how to go from Movie model to Part model and then to Actor model to retrieve the names of the actor.
could someone help me, please?

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

the Task:
Then in the Movies controller, add the show action to display a specific movie and its actors.
First use Movie.find to find the movie by its id.
Then retrieve all actors that belong to the movie, and store them in @actors.


#2

Hi!
There should be:
@actors = @movie.actor

You take actors from the movie which you described above as @movie.
And be careful, there is plural: @actors.


#3

thanks!

I put this line in movies/show/html/erb

Cast


<%= @movie.actors.each do |actor|%>


<%= image_tag actor.image %>

<%= actor.first_name %> <%= actor.last_name %>


<%= actor.bio %>


<%= link_to "Learn more", actor_path(actor) %>

<% end %>

and use find by id method in movies controller.

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


#4

I think in Movies controller in method show

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

it's enough


#5

<%= actor.first_name %> <%= actor.last_name %>
should be
<%= @actor.first_name %> <%= @actor.last_name %>


#6

Hey,
The lesson passed me with just the code

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

But you are saying that there should be an additional line, making the code look like this:

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

At least that's what I'm seeing. Am I correct or no? Cheers!