创建ActiveRecord对象时ConnectionNotEstablished

时间:2015-06-04 19:19:04

标签: ruby-on-rails rails-activerecord

我有这个简单的类Category,它对应于表格。它继承自另一个类 - Record

记录

require_relative '../../database/contract'
require 'active_record'

class Record < ActiveRecord::Base

  def initialize
    @active = true
  end

end

分类

require_relative 'record'

class Category < Record
  self.table_name = Tables::CATEGORIES

  def initialize(name)
    super()
    @name = name
  end

end

在我的一个测试端点中,我尝试创建Category对象:

get '/api/create' do
  category = Category.new('jewlery') #error here

  # this on the other hand, doesnt throw any error
  # conn = PGconn.open(:dbname => 'collector_test')
  # res  = conn.exec('select * from shoes')
end

这会抛出错误,如评论中所述。以下是stacktrace的最后一行:

/Users/jacek/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb in retrieve_connection
        raise ConnectionNotEstablished, "No connection pool for #{klass}" unless pool
/Users/jacek/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_handling.rb in retrieve_connection
      connection_handler.retrieve_connection(self)

我在database.yml中配置了这样的数据库(切断了生产和开发,因为此时我只使用测试)

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

test:
  <<: *default
  database: collector_test
  username: collector
  password: password1

我想念什么?

0 个答案:

没有答案