[英]ActiveRecord::Base.establish_connection with postgresql on AWS
When I got my database.yml configured like this: 当我像这样配置我的database.yml时:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
timeout: 5000
production:
<<: *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: 当我建立这样的连接时:
ActiveRecord::Base.establish_connection
it says ActiveRecord::AdapterNotSpecified - 'production'
它说ActiveRecord::AdapterNotSpecified - 'production'
It works hovewer If I do it like this: 它的工作原理如果我这样做是这样的:
ActiveRecord::Base.establish_connection(
{: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. 我宁愿从database.yml加载配置。 How do I do this? 我该怎么做呢?
I'm on Rails 4.2.1 and Postgres 9.4 我在Rails 4.2.1和Postgres 9.4上
Here is the working code: 这是工作代码:
db_config = YAML.load_file('config/database.yml')
ActiveRecord::Base.establish_connection(db_config['production'])
只需通过您的生产环境作为选择:
ActiveRecord::Base.establish_connection(:production)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.