Jacek Kwiecień Jacek Kwiecień - 10 months ago 70
Ruby Question

ActiveRecord::Base.establish_connection with postgresql on AWS

When I got my database.yml configured like this:

default: &default
adapter: postgresql
encoding: utf8
pool: 5
timeout: 5000

<<: *default
host: my_db_address
port: 5432
database: my_db_name
username: my_db_user_name
password: my_db_password

< test and development ommited >

When I establish connection like this:


it says
ActiveRecord::AdapterNotSpecified - 'production'

It works hovewer If I do it like this:

{:adapter => 'postgresql',
:database => 'my_db_name',
:host => 'my_db_address',
:port => '5432',
:username => 'my_db_user_name',
:password => 'my_db_password'}

I'd rather load the config from database.yml. How do I do this?

I'm on Rails 4.2.1 and Postgres 9.4

Answer Source

Here is the working code:

db_config = YAML.load_file('config/database.yml')