我有一個ENV文件與各種變量通過我的Rails應用程序依賴於,包括RAILS_ENV,這是在這個文件中初始化的發展。我也有database.yml
文件爲我的環境定義數據庫連接(見下文)。當我運行rails控制檯時,一切看起來都應該如此。檢查Rails.configuration.database_configuration[Rails.env]
返回如下:
{"adapter"=>"postgresql",
"encoding"=>"utf8",
"database"=>"dev",
"username"=>"rails",
"password"=>"***",
"host"=>"localhost",
"pool"=>5,
"timeout"=>5000}
然而,當我嘗試訪問的應用程序,我得到一個502,並記錄以下錯誤:
異常的ActiveRecord :: NoDatabaseError機架中的應用對象( FATAL:數據庫「督促」不存在
顯然,該錯誤信息是準確的,但並不代表我會想到會發生
。我假設這是一個Passenger/Apache問題,因爲運行rails控制檯一切都很開心。
注意:我已經看到這個在其他帖子中出現,所以沒有 - 沒有DATABASE_URL
環境變量浮動在從database.yml
重寫的東西周圍。
我已經試過
.bashrc
:Passenger is supposed to source the bashrc for the user apache is running as,這又是設置到源相關ENV文件。/etc/sysconfig/httpd
:我已經試過手動直接從Apache配置採購文件和傾倒ENV腳本運行正確的值使它成爲了ENV,但是這也不會改變正常的行爲時,文件驗證。
的database.yml
development:
adapter: postgresql
encoding: utf8
database: dev
username: rails
password: <%= ENV['RAILS_DB_PWD'] %>
host: <%= ENV['RAILS_DB_HOST'] %>
pool: 5
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:
adapter: postgresql
encoding: utf8
database: test
username: rails
password: <%= ENV['RAILS_DB_PWD'] %>
host: <%= ENV['RAILS_DB_HOST'] %>
pool: 5
timeout: 5000
production:
adapter: postgresql
encoding: utf8
database: prod
username: rails
password: <%= ENV['RAILS_DB_PWD'] %>
host: <%= ENV['RAILS_DB_HOST'] %>
port: 5432
pool: 5
timeout: 5000
呵呵。那就是訣竅。沒有意識到您在公共塊中使用的符號。 – Dan