Undefined method `each' for nil:NilClass

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
	def show
    @actor = Actor.find(params[:id])
    @movies = @actor.movies

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>

    <% @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>


Any help would be appreciated and thanks in advance!

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…
Movies II (5.3) 'Each' Error

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