Rails呈现集合不工作-未定义的局部变量或方法



我正在尝试创建一个提要,显示一个模型的所有评论。

_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 %>

_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>
上面的代码给了我一个未定义的局部变量或方法' comment'错误。当局部用于呈现注释集合时,rails不是自动生成注释吗?

局部变量的名称对应于局部变量的名称。在您的例子中,本地变量将被命名为comment_feed

最新更新