我有一个包含文章和评论的应用程序(教程)。一篇文章有_许多评论。评论属于文章。我在删除文章评论时遇到问题。以下是有问题的文件:
app/views/comments/_comment.html.erb
<%= div_for comment do %>
<h3>
<%= comment.name %> <<%= comment.email %>> said:
<span class='actions'>
<%= link_to 'Delete', [@article, comment], confirm: 'Are you sure?', method: :delete %>
</span>
</h3>
<%= comment.body %>
<% end %>
评论控制器
before_filter :load_article
def create
@comment = @article.comments.new(params[:comment])
if @comment.save
redirect_to @article, :notice => 'Thanks for your comment'
else
redirect_to @article, :alert => 'Unable to add comment'
end
end
def destroy
@comment = @article.comments.find(params[:id])
@comment.destroy
redirect_to @article, :notice => 'Comment deleted'
end
private
def load_article
@article = Article.find(params[:article_id])
end
路线.rb
resources :articles do
resources :comments
end
问题是当我在地址localhost:3000/articles/1并尝试删除评论时。我没有被重定向到文章显示操作,而是在地址localhost:3000/articles/1/comments/3处收到此错误:
Unknown action
The action 'show' could not be found for CommentsController
非常感谢任何帮助,谢谢,迈克