The code still does not work. any idea why?


but the code still does not work. any idea why?


undefined method `Actors' for nil:NilClass

class MoviesController < ApplicationController
  def index
    @movies = Movie.all
  def show
    @movies = Movie.find(params[:id])
    @actors = @movie.actors

Hi @orouge,


This means that the variable is undefined. Check that part carefully.

hey @zystvan

I seem to struggle through this question Still. for example in the following code, why while creating image for movie we use “@” ; however, in the case of creating image for actor we don’t!
Thanks in advance!

<div class="main movie-show">
  <div class="container">
    <div class="movie">
      <!-- Display the movie's info here -->
      <div class="info">
        <%= image_tag @movie.image %>
        <h3 class="movie-title"><%= @movie.title %></h3>
        <p class="movie-release-year"><%= @movie.release_year %></p>
        <p class="movie-plot"><%= @movie.plot %></p>

    <% @actors.each do |actor| %>
    <div class="actor">
      <%= image_tag actor.image %>
      <h3 class="actor-name"><%= actor.first_name %> <%= actor.last_name %></h3>
      <p class="actor-bio"><%= %></p>
		<% end %>

@orouge @movie is the current movie, defined in your controller code. actor is the current actor, in an array of actors that you’re looping through.

Taking the Ruby course will help you understand this stuff better :slight_smile:

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