nil:NilClass的未定义方法“作者”

种族

我的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 %>

这将输出如下内容:#<Chapter:0x007fa1b8f59888>

我真正想做的是:

<% chosenChapters.each do |chosenChapter| %>
    <%= chosenChapter.author %>
<% end %>

但是,每当我尝试访问selectedChapter内部的属性之一时,都会收到以下错误消息:

undefined method `author' for nil:NilClass

我究竟做错了什么?谢谢!

马里克·利普卡

你们中至少有一个chosenChaptersnil问题可能出在以下片段中:

<% maxVotes = chapter.votes.count %>
<% chosenChapterRound = chapter.round %>
<% chosenChapters[round.to_i] = chapter %>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章