【发布时间】:2014-07-22 11:33:32
【问题描述】:
我的 rails 应用程序有一些问题。
<% @story.chapters.each do |chapter| %>
<% if round.to_s != chapter.round %>
<% if chosenChapterRound != chapter.round %>
<% maxVotes = 0 %>
<% end %>
<% if chapter.votes.count > maxVotes %>
<% maxVotes = chapter.votes.count %>
<% chosenChapterRound = chapter.round %>
<% chosenChapters[round.to_i] = chapter %>
<% end %>
<% end %>
<% end %>
<% chosenChapters.each do |chosenChapter| %>
<%= chosenChapter %>
<% end %>
这会输出如下内容:#
我真正想做的是:
<% chosenChapters.each do |chosenChapter| %>
<%= chosenChapter.author %>
<% end %>
但每当我尝试访问 selectedChapter 中的某个属性时,我都会收到以下错误消息:
undefined method `author' for nil:NilClass
我做错了什么?谢谢!
【问题讨论】:
标签: ruby-on-rails erb