rails rendering collection not working - undefined local variable or method

jee*_*ace 1 ruby-on-rails

我正在尝试创建一个显示模型所有注释的Feed.

_comments.html.erb

<% if @comments.any? %>
    <ol>
      <%= render partial: 'shared/comment_feed', collection: @comments %>
    </ol>
    <%= will_paginate @comments %>
<% else %>
    <h2>Be the first one to comment on this episode!</h2>
<% end %>
Run Code Online (Sandbox Code Playgroud)

_comment_feed.html.erb

<li id="<%= comment.id %>">
  <%= link_to gravatar_for(comment.user), comment.user %>
  <span class="user">
    <%= link_to comment.user.name, comment.user %>
  </span>
  <span class="content"><%= simple_format comment.content %></span>
  <span class="timestamp">
    Posted <%= time_ago_in_words(comment.created_at) %> ago.
  </span>
  <% if current_user?(comment.user) %>
    <%= link_to "delete", comment, method: :delete,
                                   confirm: "Are you sure?",
                                   title: comment.content %>
  <% end %> 
</li>
Run Code Online (Sandbox Code Playgroud)

上面的代码给了我一个未定义的局部变量或方法`comment'错误.当使用partial来呈现注释集合时,rails不会自动生成注释吗?任何帮助将不胜感激.

Pet*_*own 5

局部变量的名称对应于partial的名称.在您的情况下,将命名局部变量comment_feed.