I’ve been browsing the forums and have found a lot of solutions to my syntax errors but I’m still having trouble solving the error I get in the title of this post: “undefined ‘name’ for nil:NilClass”. I’ve searched my files for the “name” method but have not been able to locate it. I submitted a bug report after seeing a similar post with no resolution. It was dated for 2017 so I was hoping to have some help troubleshooting or find out whether there’s a work around besides the “Solution” button. Using the “Solution” button also hasn’t filled in the code it just clears the steps for me to move forward.
class MoviesController < ApplicationController def index @movies = Movie.all end def show @movie = Movie.find(params[:id]) @actors = @movie.actors end end
show.html.erb for Movies
<!-- movie image --> <%= 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> </div> </div> <h2>Cast</h2> <!-- Display each actor's info here --> <% @actors.each do |a| %> <div class="actor"> <!-- actor image --> <%= a.image %> <h3 class="actor-name"><%= a.first_name + ' ' + a.last_name %> </h3> <p class="actor-bio"> <%= a.bio %> </p> <% end %> </div>