【发布时间】:2017-12-29 20:42:58
【问题描述】:
当我删除评论时,我看到了
nil:NilClass 的未定义方法 'each'
另外,用户不能删除他的帐户,如果已经发布...它会出错。
这是代码
<p id="notice"><%= notice %></p>
<h1>Comments</h1>
<table>
<thead>
<tr>
<th>Link</th>
<th>Body</th>
<th>User</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @comments.each do |comment| %>
<tr>
<td><%= comment.link_id %></td>
<td><%= comment.body %></td>
<td><%= comment.user %></td>
<td><%= link_to 'Show', comment %></td>
<td><%= link_to 'Edit', edit_comment_path(comment) %></td>
<td><%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Comment', new_comment_path %>
【问题讨论】:
-
你能分享你
CommentsController的代码吗?更具体地说,销毁操作。 -
请分享您的控制器代码。它将帮助我们更多地回答。
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-3.2