【问题标题】:PG ERROR: invalid input syntax for integer when trying to destroyPG 错误:尝试销毁时整数的输入语法无效
【发布时间】:2019-08-22 11:40:19
【问题描述】:

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

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

【问题讨论】:

  • 我看到当参数超出预期位置时会发生此错误。
  • @JSpratt,我不确定你的意思。我用我尝试过的另一件事更新了我的问题。
  • 你可以发布应用程序日志@ddonche 吗?

标签: ruby-on-rails postgresql


【解决方案1】:

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

【讨论】:

猜你喜欢
  • 2013-08-20
  • 2018-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-30
  • 2014-07-17
  • 1970-01-01
相关资源
最近更新 更多