为什么程序不能运行?
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.namedatabase.yml
default: &default
adapter: sqlite3
encoding: unicode
pool: 5
development:
<<: *default
database: my_database_namelist.db
sqlite> select *从学生;
123|foo|foo@email.com错误
../activerecord-5.0.0.1/lib/active_record/connection_adapters/connection_specification.rb:170:in `spec': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)发布于 2017-04-19 20:12:15
在我的例子中,我使用一个字符串来标识我想要使用的数据库配置,而不是一个符号(这似乎是Rails5所需要的)
试试这个:
ActiveRecord::Base.establish_connection(:development)
https://stackoverflow.com/questions/40586645
复制相似问题