2016-11-14 72 views
0

爲什麼程序不運行?ActiveRecord的配置錯誤 - ActiveRecord :: AdapterNotSpecified

list.rb

require 'active_record' 
require 'yaml' 

ActiveRecord::Base.configurations = YAML.load_file('./database.yml') 
ActiveRecord::Base.establish_connection('development') 

class Student < ActiveRecord::Base 
end 

student = Student.find('123') 
puts student.id 
puts student.name 

的database.yml

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

development: 
    <<: *default 
    database: my_database_name 

list.db

sqlite的> SELECT * FROM學生;

123|foo|[email protected] 

錯誤

../activerecord-5.0.0.1/lib/active_record/connection_adapters/connection_specification.rb:170:in `spec': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified) 
+2

可能重複的[ActiveRecord :: AdapterNotSpecified databas e配置不指定適配器](http://stackoverflow.com/questions/23336755/activerecordadapternotspecified-database-configuration-does-not-specify-adapte) – fabersky

+0

我已經更改爲上述database.yml但錯誤再次發生。 – faara

回答

0

在我來說,我使用的是字符串標識數據庫的配置我想用的,而不是一個符號(該導軌5似乎需要)

試試這個:

ActiveRecord::Base.establish_connection(:development)

相關問題