【问题标题】:ActiveRecord::StatementInvalid in ContactController rails & postgresqlContactController rails 和 postgresql 中的 ActiveRecord::StatementInvalid
【发布时间】:2017-02-13 16:22:18
【问题描述】:

当我尝试从表中创建/编辑或销毁联系人时出现错误。

当我尝试创建/编辑时,我有:

ActiveRecord::StatementInvalid in ContactController#create

PG::UndefinedFunction: 错误: 函数 get_xmlbinary() 不存在 第 1 行:SELECT (get_xmlbinary() = 'base64') ^ 提示:无功能 匹配给定的名称和参数类型。您可能需要添加 显式类型转换。查询:选择(get_xmlbinary()='base64') 上下文:PL/pgSQL 函数 hc_contact_status() 第 3 行,位于 IF:INSERT INTO“联系人”(“姓氏”、“名字”、“姓名”、“电话”、“电子邮件”) 值(1 美元、2 美元、3 美元、4 美元、5 美元)返回“id”

当我尝试删除时:

ActiveRecord::StatementInvalid in ContactController#create

PG::UndefinedFunction: 错误: 函数 hstore(contact) 不存在 第 1 行:选择 hstore(OLD.) - exclude_cols ^ 提示:无功能 匹配给定的名称和参数类型。您可能需要添加 显式类型转换。 QUERY: SELECT hstore(OLD.) - exclude_cols 上下文:PL/pgSQL 函数 hc_contact_logger() 第 18 行分配: DELETE FROM "contact" WHERE "contact"."id" = $1

我跟着 guide 将“hstore”添加到我的 application_db 但它显示 ERROR: extension "hstore" already exists

我正在处理现有数据库 (Salesforce)。我使用命令行rails generate scaffold contact 获取模型控制器和视图,并且可以在浏览器上显示数据库的内容。

contact_controller.rb:

class ContactController < ApplicationController
  before_action :set_contact, only: [:show, :edit, :update, :destroy]

  # GET /contacts
  # GET /contacts.json
  def index
    @contact = Contact.all
  end

  # GET /contacts/1
  # GET /contacts/1.json  
  def show
  end

  # GET /contacts/new
  def new
    @contact = Contact.new
  end

  # GET /contacts/1/edit
  def edit
  end

  # POST /contacts
  # POST /contacts.json
  def create
    @contact = Contact.new(contact_params)

    respond_to do |format|
      if @contact.save
        format.html { redirect_to @contact, notice: 'Contact was successfully created.' }
        format.json { render :show, status: :created, location: @contact }
      else
        format.html { render :new }
        format.json { render json: @contact.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /contacts/1
  # PATCH/PUT /contacts/1.json
  def update
    respond_to do |format|
      if @contact.update(contact_params)
        format.html { redirect_to @contact, notice: 'Contact was successfully updated.' }
        format.json { render :show, status: :ok, location: @contact }
      else
        format.html { render :edit }
        format.json { render json: @contact.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /contacts/1
  # DELETE /contacts/1.json
  def destroy
    @contact.destroy
    respond_to do |format|
      format.html { redirect_to @contact, notice: 'Contact was successfully destroyed.' }
      format.json { head :no_content }
    end
  end
  #contact_url

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_contact
      @contact = Contact.find(params[:id])
    end


    # Never trust parameters from the scary internet, only allow the white list through.
    def contact_params
      params.require(:contact).permit(:name, :lastname, :firstname, :phone, :email)
    end
end

可能是什么?不要犹豫,询问您是否需要其他文件

编辑:我在 PSQL 上找到了它:

hc_contact_logtrigger 插入、删除或更新后 salesforce.contact FOR 每一行 WHEN (get_xmlbinary()::text = 'base64'::text) 执行过程 salesforce.hc_contact_logger()

hc_contact_status_trigger 在插入或更新之前 salesforce.contact 每一行执行程序 salesforce.hc_contact_status()

schema.rb

ActiveRecord::Schema.define(version: 0) do

  enable_extension "plpgsql"
  enable_extension "hstore"

  create_table "_hcmeta", force: :cascade do |t|
    t.string  "org_id",  limit: 50
    t.text    "details"
    t.integer "hcver"
  end

  create_table "_sf_event_log", force: :cascade do |t|
    t.string   "table_name",   limit: 128
    t.string   "action",       limit: 7
    t.datetime "synced_at",                default: -> { "now()" }
    t.datetime "sf_timestamp"
    t.string   "sfid",         limit: 20
    t.text     "record"
    t.boolean  "processed"
    t.index ["sfid"], name: "idx__sf_event_log_sfid", using: :btree
    t.index ["table_name", "synced_at"], name: "idx__sf_event_log_comp_key", using: :btree
  end

  create_table "_trigger_last_id", id: false, force: :cascade do |t|
    t.integer "trigger_log_id"
  end

  create_table "_trigger_log", force: :cascade do |t|
    t.string   "table_name",   limit: 128
    t.string   "state",        limit: 8
    t.string   "sfid",         limit: 18
    t.datetime "processed_at"
    t.string   "action",       limit: 7
    t.datetime "updated_at",               default: -> { "now()" }
    t.text     "old"
    t.bigint   "txid"
    t.integer  "record_id"
    t.text     "sf_message"
    t.datetime "created_at",               default: -> { "now()" }
    t.text     "values"
    t.integer  "sf_result"
    t.bigint   "processed_tx"
    t.index ["created_at"], name: "_trigger_log_idx_created_at", using: :btree
    t.index ["state", "id"], name: "_trigger_log_idx_state_id", using: :btree
    t.index ["state", "table_name"], name: "_trigger_log_idx_state_table_name", where: "(((state)::text = 'NEW'::text) OR ((state)::text = 'PENDING'::text))", using: :btree
  end

  create_table "_trigger_log_archive", id: :integer, force: :cascade do |t|
    t.string   "table_name",   limit: 128
    t.string   "state",        limit: 8
    t.string   "sfid",         limit: 18
    t.datetime "processed_at"
    t.string   "action",       limit: 7
    t.datetime "updated_at"
    t.text     "old"
    t.bigint   "txid"
    t.integer  "record_id"
    t.text     "sf_message"
    t.datetime "created_at"
    t.text     "values"
    t.integer  "sf_result"
    t.bigint   "processed_tx"
    t.index ["created_at"], name: "_trigger_log_archive_idx_created_at", using: :btree
    t.index ["record_id"], name: "_trigger_log_archive_idx_record_id", using: :btree
    t.index ["state", "table_name"], name: "_trigger_log_archive_idx_state_table_name", where: "((state)::text = 'FAILED'::text)", using: :btree
  end

  create_table "contact", force: :cascade do |t|
    t.string   "lastname",       limit: 80
    t.string   "firstname",      limit: 40
    t.string   "_hc_lastop",     limit: 32
    t.datetime "systemmodstamp"
    t.string   "name",           limit: 121
    t.text     "_hc_err"
    t.string   "sfid",           limit: 18
    t.string   "phone",          limit: 40
    t.boolean  "isdeleted"
    t.datetime "createddate"
    t.string   "email",          limit: 80
    t.index ["sfid"], name: "hcu_idx_contact_sfid", unique: true, using: :btree
    t.index ["systemmodstamp"], name: "hc_idx_contact_systemmodstamp", using: :btree
  end

  create_table "product2", force: :cascade do |t|
    t.text     "productimage__c"
    t.datetime "createddate"
    t.datetime "systemmodstamp"
    t.boolean  "isdeleted"
    t.string   "sfid",            limit: 18
    t.string   "name",            limit: 255
    t.string   "family",          limit: 40
    t.string   "_hc_lastop",      limit: 32
    t.string   "description",     limit: 4000
    t.string   "productcode",     limit: 255
    t.text     "_hc_err"
    t.index ["sfid"], name: "hcu_idx_product2_sfid", unique: true, using: :btree
    t.index ["systemmodstamp"], name: "hc_idx_product2_systemmodstamp", using: :btree
  end

end

【问题讨论】:

  • 你的schema.rb有什么?
  • 我解决了,不幸的是我真的不知道怎么解决,所以我无能为力。我发布了 mu schema.rb,它可以帮助有问题的人

标签: ruby-on-rails postgresql activerecord model-view-controller


【解决方案1】:

您需要将“公共”模式包含到您的 schema_search_path 到 database.yml 中

default: &default
  ...........
  schema_search_path: "salesforce,public"

Connect 在您的数据库的 public 架构中创建一个名为 get_xmlbinary 的函数,并将其用作同步过程的一部分。如果您从 search_path 中删除 public 架构,Connect 将无法找到该函数,并且同步将失败。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-31
    • 2013-09-06
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多