but the code still does not work. any idea why?
undefined method `Actors' for nil:NilClass
class MoviesController < ApplicationController
@movies = Movie.all
@movies = Movie.find(params[:id])
@actors = @movie.actors
This means that the variable is undefined. Check that part carefully.
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">
<!-- Display the movie's info here -->
<%= 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| %>
<%= image_tag actor.image %>
<h3 class="actor-name"><%= actor.first_name %> <%= actor.last_name %></h3>
<p class="actor-bio"><%= actor.bio %></p>
<% end %>
@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
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.