2016-03-12 105 views
0

我想部署使用mysql數據庫的我的Rails 4應用程序。數據庫位於不同的服務器上。Cloud Foundry - Rails 4 database.yml

我很困惑,應該如何配置我的database.yml文件,以及雲代工廠如何知道要使用哪個部分。

部署後,我裝我的應用程序

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 

回答

0

原來我需要此在application.rb中:

ENV [ 'DATABASE_URL'] = 'mysql2://用戶名:密碼@主機名:3306/DBNAME'

0

如果您在生產模式下運行rails應用程序。配置就是這樣的。

production: 
    adapter: postgresql 
    encoding: utf8 
    database: rails_myapp 
    username: rails_myapp_user 
    password: pwd 
    host: 128.199.233.36 
    port: 5432 
    pool: 10 
+0

我在內部託管CF.部署到開發環境它如何知道要使用什麼> – user3437721

+0

意味着你不知道數據庫服務器信息? –

+0

雲代工廠如何知道使用哪個條目形成database.yml文件 – user3437721

0

考慮設置數據庫URL作爲CF的環境變量:

cf set-env <app-name> DATABASE_URL 'mysql2://username:[email protected]:3306/dbname'