0

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
ddonche
  • 1,065
  • 2
  • 11
  • 24

1 Answers1

0

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

dmrlps
  • 72
  • 1
  • 9
  • 1
    I'm not sure what you mean here. I am destroying this like I destroy all the other things. In fact, I use the code exactly the way it's done in the [Rails Tutorial by Michael Hartl](https://www.railstutorial.org/book/updating_and_deleting_users). I was under the impression you find the record by its id and then destroy it. Is that not what's supposed to happen? – ddonche Aug 22 '19 at 04:04
  • I think this will solve your problem https://stackoverflow.com/questions/20715190/pginvalidtextrepresentation-error-invalid-input-syntax-for-integer-m – dmrlps Aug 22 '19 at 05:42