简体   繁体   中英

PG ERROR: invalid input syntax for integer when trying to destroy

I get this error whenever I try to destroy a record. I don't get why this isn't working.

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

My controller:

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

I've also tried doing it this way:

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

How I'm doing it in the view:

 <%= 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 %>

The schema:

  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

I think you are passing "Notation" as :id in your destroy path. Try double checking your comment_notation_path(@comment, notation) path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM