Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails / ActiveRecord - AdapterNotSpecified, even though it is

I'm doing the Ruby on Rails Tutorial. For the first three chapters it uses SQLite, but later it suggests using PostgreSQL on development for easier Heroku deploys. After editing my database.yml and Gemfile to use pg instead of sqlite3, it seems to work - except when using Rake to run a test. It pops out an AdapterNotSpecified error.

C:/Ruby/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/lib/active_record/ connection_adapters/connection_specification.rb:52:in resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecif ied)

etc.

The database.yml specifies an adapter, like so:

development:
  adapter: postgresql
  host: localhost
  username: nekkoru
  password: derpderp
  database: development
  encoding: UTF8

What's going on? I'm on Windows 7 x64, Ruby 1.9.3, Rails 4.0.0, PostgreSQL 9.3.0.1.

like image 770
Nekkoru Avatar asked Sep 28 '13 12:09

Nekkoru


2 Answers

You did not define the database for the test environment. Your database.yml file should look like:

development:
  adapter: postgresql
  host: localhost
  username: nekkoru
  password: derpderp
  database: development
  encoding: UTF8

test:
  adapter: postgresql
  host: localhost
  username: nekkoru
  password: derpderp
  database: test        # or whatever the name is
  encoding: UTF8
like image 84
spickermann Avatar answered Oct 14 '22 22:10

spickermann


Indentation was the culprit for me.

Rails it seems has a strict way of reading db type (development or production) and the db settings (adapter, host, username, etc etc) from the yml file.

But of course the ActiveRecord error msg was overkill.. it made it look like I was missing a gem

like image 22
Red Avatar answered Oct 14 '22 21:10

Red