0

Why doesn't the program run?

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 students;

123|foo|foo@email.com

error

../activerecord-5.0.0.1/lib/active_record/connection_adapters/connection_specification.rb:170:in `spec': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
faara
  • 159
  • 1
  • 1
  • 5
  • 2
    Possible duplicate of [ActiveRecord::AdapterNotSpecified database configuration does not specify adapter](http://stackoverflow.com/questions/23336755/activerecordadapternotspecified-database-configuration-does-not-specify-adapte) – fabdurso Nov 14 '16 at 11:00
  • I've changed to above database.yml but the error happened again. – faara Nov 17 '16 at 15:16

1 Answers1

0

In my case I was using a string to identify the database config I wanted to use instead of a symbol (which Rails 5 seems to require)

Try this:

ActiveRecord::Base.establish_connection(:development)

Josh
  • 366
  • 2
  • 8
  • 20