Rails 找不到 'id'=27 [WHERE "parts"."active" = ?] RecordNotFound in PartsController#Destroy 的零件

Rails Couldn't find Part with 'id'=27 [WHERE "parts"."active" = ?] RecordNotFound in PartsController#Destroy

我正在尝试为我网站上的用户创建一种删除评论的方法。我已经这样设置了我的视图

<li><%= comment.content%> by: <%= comment.user.first_name %> </li>
<% if logged_in? %>
<%=link_to 'delete', part_comment_path(@part, comment), data: {confirm: "Are you sure you want to delete this comment?"}, method: 'DELETE'%>
<%end%>

当我单击删除 link 时,我收到来自零件控制器的错误 "Couldn't find Part with 'id'=27 [WHERE "parts"."active" = ?]"。目前我的 Comments 控制器是这样设置的。

class CommentsController < ApplicationController
  def create
    part = Part.find(params[:part_id])
    @comment = part.comments.create(comment_params.merge(user: current_user))

    respond_to do |format|
      format.html {redirect_to part}
      format.js{}
  end
end

  def destroy
    @part = Part.find(params[:part_id])
    @comment = @part.comments.find(params[:id])
    @comment.destroy
      format.html {redirect_to part}
      format.js{}
  end

private
def comment_params
  params.require(:comment).permit(:content)
  end
end

我的零件控制器是这样设置的

class PartsController < ApplicationController
  before_filter :authorize, :except => [:index, :show]

  def index
    @parts = Part.all
    @categories = Category.all
    @parts = @parts.search(params[:search]) if params[:search].present?
  end

  def new
    @part = Part.new
  end

  def show
    @part = Part.find(params[:id])
  end

  def create
    @part = Part.new(part_params)
      if @part.save
        redirect_to part_path(@part)
  end
end

  def edit
    @part = Part.find(params[:id])
  end

  def update
    @part = Part.find(params[:id])
      if @part.update_attributes(part_params)
        redirect_to @part
      end
    end

    def destroy
      @part = Part.find(params[:id])
      @part.destroy
        redirect_to parts_path
    end

  private
  def part_params
    params.require(:part).permit(:description, :name, :price, :active, :avatar, :discount, :category_id)
  end
end

我的评论路线是嵌套的

resources :parts do
    resources :comments, only: [:create, :destroy]
  end

我的模型被安排成一个评论 belongs_to 一个部分和一个部分 has_many 评论。感谢您对此的帮助

我认为删除方法不起作用。尝试使用此 <%=link_to 'delete', part_comment_path(@part, comment), data: {confirm: "Are you sure you want to delete this comment?"},方法::delete>。并检查是否有任何其他评论