Undefined method `each' for nil:NilClass


#1

I dont understand why but I keep getting the error above for Actors I part 7.

My controller is :

class ActorsController < ApplicationController
	def index
		@actors = Actor.all
	end
	
	def show
    @actor = Actor.find(params[:id])
    @movies = @actor.movies
  end
end

My show.html.erb is:

<div class="main actor-show">
  <div class="container">
    <% @actors.each do |actor| %>
    <!-- Display an actor's info here -->
    <div class="actor">
      <%= image_tag actor.image %>
      <!-- actor image -->
      <div class="info">
        <h3 class="actor-name"><%= actor.first_name %> <%= actor.last_name %>  </h3>
        <p class="actor-bio"> <%= actor.bio %> <%end%> </p>
      </div>
    </div>

    <h2>Movies</h2>
    <% @movies.each do |m| %>
    <!-- Display each movie's info here -->
    <div class="movie">
      <!-- movie image -->
      <%= image_tag m.image %>
      <h3 class="movie-title"> <%= m.title %> </h3>
      <p class="movie-release-year"> <%= m.release_year %> </p>
      <p class="movie-plot"> <%= m.plot %><%end%> </p>
    </div>

  </div>
</div>

Any help would be appreciated and thanks in advance!


#2

Missing or misplace end tag on @actors loop.

Actually, I did a little digging and the movie is not a loop. Just @movie. See @zystvan's post here...
https://discuss.codecademy.com/t/movies-ii-5-3-each-error/46446/5


#3

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