THIS IS THE VIEW FILE FOR SHOW METHOD: it is a simple project for adding movie with its review,ticket count and displaying it. I get an error in the #3 line. Pls help me with it.
error :You have a nil object when you didn't expect it! The error occurred while evaluating nil.name
<h1><%= @movie.title %></h1>
<p><strong>Ticket count: </strong> $<%= @movie.ticket_count %><br />
<strong>Language: </strong> <%= link_to @movie.language.name, :action => "show_lang", :id => @movie.language.id %><br />
<strong>Created Date:</strong> <%= @movie.created_at %><br />
</p>
<p><%= @movie.review %></p>
<hr />
<%= link_to 'Back', {:action => 'list'} %>
@movie.language
is nil. make sure the language is set for the movie.
The best practice is to use delegate
in Movie
For more information:
According to the law of demeter, a model should only talk to its immediate association, don't talk to the association's association and association's property, it is a case of loose coupling.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.