云铸造厂 - Rails 4 database.yml
Cloud Foundry - Rails 4 database.yml
我正在尝试部署使用 mysql 数据库的 Rails 4 应用程序。数据库托管在不同的服务器上。
我很困惑我的 database.yml 文件应该如何配置,cloud foundry 如何知道要使用哪个部分。
部署后,加载我的应用程序时出现此错误
ActiveRecord::AdapterNotSpecified
'' database is not configured. Available: ["development"]
Rails.root: /home/vcap/app
如果您随后刷新页面,您会得到:
NoMethodError
undefined method `default_timezone=' for #<Class:0x007fd7930ab0f0>
Rails.root: /home/vcap/app
我的database.yml是这样的:
#local development
development:
adapter: mysql2
encoding: utf8
host: hostname
port: 3306
database: appdb
username: myapp
password: 'password'
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: &test
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: mysql2
encoding: utf8
host: hostname
port: 3306
database: appdb
username: myapp
password: 'password'
timeout: 5000
如果您 运行 处于生产模式的 rails 应用程序。配置会是这样的。
production:
adapter: postgresql
encoding: utf8
database: rails_myapp
username: rails_myapp_user
password: pwd
host: 128.199.233.36
port: 5432
pool: 10
原来我需要这个 application.rb:
ENV['DATABASE_URL'] = 'mysql2://username:password@hostname:3306/dbname'
考虑将数据库 url 设置为 CF 中的环境变量:
cf set-env <app-name> DATABASE_URL 'mysql2://username:password@hostname:3306/dbname'
我正在尝试部署使用 mysql 数据库的 Rails 4 应用程序。数据库托管在不同的服务器上。
我很困惑我的 database.yml 文件应该如何配置,cloud foundry 如何知道要使用哪个部分。
部署后,加载我的应用程序时出现此错误
ActiveRecord::AdapterNotSpecified
'' database is not configured. Available: ["development"]
Rails.root: /home/vcap/app
如果您随后刷新页面,您会得到:
NoMethodError
undefined method `default_timezone=' for #<Class:0x007fd7930ab0f0>
Rails.root: /home/vcap/app
我的database.yml是这样的:
#local development
development:
adapter: mysql2
encoding: utf8
host: hostname
port: 3306
database: appdb
username: myapp
password: 'password'
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: &test
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: mysql2
encoding: utf8
host: hostname
port: 3306
database: appdb
username: myapp
password: 'password'
timeout: 5000
如果您 运行 处于生产模式的 rails 应用程序。配置会是这样的。
production:
adapter: postgresql
encoding: utf8
database: rails_myapp
username: rails_myapp_user
password: pwd
host: 128.199.233.36
port: 5432
pool: 10
原来我需要这个 application.rb:
ENV['DATABASE_URL'] = 'mysql2://username:password@hostname:3306/dbname'
考虑将数据库 url 设置为 CF 中的环境变量:
cf set-env <app-name> DATABASE_URL 'mysql2://username:password@hostname:3306/dbname'