不能破坏评论工作(RAILS)

时间:2015-03-05 20:49:00

标签: ruby-on-rails

所以这是我第一次使用Rails,我根据http://guides.rubyonrails.org/getting_started.html#generating-a-model

做了一切

现在我无法破坏一个通讯......我尝试了几次谷歌搜索,我试图删除该文件然后再次生成它,没有任何作用...我的comments_controller.rb

class CommentsController < ApplicationController
  def index
  end

  def show
  end

  def new
  end

  def edit
  end

  def create
    @article = Article.find(params[:article_id])
    @comment = @article.comments.create(comment_params)
    redirect_to article_path(@article)
  end

  def destroy
    @article = Article.find(params[:article_id])
    @comment = @article.comments.find(params[:id])
    @comment.destroy!
    redirect_to article_path(@article)                      
  end

  private
    def comment_params
      params.require(:comment).permit(:commenter, :body)
    end

end

    p>
  <strong>Commenter:</strong>
  <%= comment.commenter %>
</p>
 

我的_comment.html.erb是

<p>
  <strong>Comment:</strong>
  <%= comment.body %>
</p>
 
<p>
  <%= link_to 'Delete the comment', [comment.article, comment],
               method: :delete,
               data: { confirm: 'Are you sure?' } %>
</p>

当我点击&#34;删除评论&#34;按钮

Missing template comments/show, application/show with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "/root/blog/app/views"

但是,由于我正在重定向到文章路径,这不应该是问题吗?对?? 我当然希望这是一个错字,但现在我无法找到它......

编辑:这是按钮的文本

<form action="/articles/2/comments/1" class="button_to" method="post">    <div><input type="submit" value="Delete the comment"  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data="{:confirm=>&quot;Are you sure?&quot;}" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method="delete"><input name="authenticity_token" type="hidden" value="rW+wymZlJp2cMrhGUX31Y/vLz+qZ1VHTEVHaavS7YTU="></div></form>

1 个答案:

答案 0 :(得分:0)

看起来像方法:删除链接无效。

确保您已启用javascript并添加

<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>

到你的布局/应用程序的<head>