[英]Action controller exception in Ruby on rails
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.
#3行出现错误。 Pls help me with it.
请帮我。
error :You have a nil object when you didn't expect it! 错误:您没想到有一个零对象! The error occurred while evaluating nil.name
评估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. @movie.language
为零。 make sure the language is set for the movie. 确保为电影设置了语言。
The best practice is to use delegate
in Movie 最佳做法是在电影中使用
delegate
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耳定律,模型仅应与其直接关联联系,而不得与该协会的联系和协会的财产联系,这是一种松散耦合的情况。
http://rails-bestpractices.com/posts/15-the-law-of-demeter http://rails-bestpractices.com/posts/15-the-law-of-demeter
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.