PG错误:尝试销毁时整数的无效输入语法

时间:2019-08-22 01:36:54

标签: ruby-on-rails postgresql

每当我尝试销毁记录时都会收到此错误。我不明白为什么这不起作用。

PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "Notation"

我的控制器:

  def destroy
    Notation.find(params[:id]).destroy
    respond_to do |format|
      format.html { redirect_to @commentable, notice: 'Reply was eradicated.' }
    end
  end

我也尝试过这种方式:

  def destroy
    @notation = Notation.find(params[:id])
    @notation.destroy
    respond_to do |format|
      format.html { redirect_to @commentable, notice: 'Reply was eradicated.' }
    end
  end

我在视图中的操作方式:

 <%= link_to comment_notation_path(@comment, notation), method: :delete, data: { confirm: "Are you sure?" } do %>
            <i class="fa fa-trash small ml-3" title="delete"></i><% end %>

架构:

  create_table "notations", force: :cascade do |t|
    t.integer "comment_id"
    t.integer "user_id"
    t.text "content"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

1 个答案:

答案 0 :(得分:0)

我认为您正在:id路径中以destroy的形式传递“符号”。尝试仔细检查您的comment_notation_path(@comment, notation)路径