orouge
July 13, 2016, 4:21pm
1
@rodmichelini
but the code still does not work. any idea why?
error
undefined method `Actors' for nil:NilClass
class MoviesController < ApplicationController
def index
@movies = Movie.all
end
def show
@movies = Movie.find(params[:id])
@actors = @movie.actors
end
end
Hi @orouge ,
nil:NilClass
This means that the variable is undefined. Check that part carefully.
orouge
July 13, 2016, 5:20pm
3
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>
</div>
</div>
<h2>Cast</h2>
<% @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"><%= actor.bio %></p>
</div>
<% end %>
</div>
</div>
@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
system
Closed
July 20, 2016, 7:21pm
5
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.