Rails / ActiveRecord - AdapterNotSpecified, although this

I am doing a Ruby on Rails Tutorial. In the first three chapters, he uses SQLite, but later he suggests using PostgreSQL for development to simplify the deployment of Heroku. After editing my database.yml and Gemfile to use pg instead of sqlite3, it seems to work, except when using Rake to run the test. It throws 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)

and etc.

An adapter is specified in the .yml database, for example:

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

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

+6
source share
2 answers

You have not defined a database for the test environment. Your database.yml file should look like this:

 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 
+12
source

Indentation was the culprit for me.

Rails seems to have a strict way to read db type (development or production) and configure db (adapter, host, username, etc. etc.) from the yml file.

But of course, the ActiveRecord error message was too large, and it looked like I was missing a gem

+6
source

Source: https://habr.com/ru/post/954837/


All Articles