我更改了我的database.yml,以便在測試和開發中使用sqlite3數據庫,並在生產中使用postgresql。我的應用程序運行在生產正常,但當我啓動測試或開發environements我有這樣的錯誤:無法加載'rails.application.database_configuration'undefined方法'[]'爲零:NilClass
Cannot load 'Rails.application.database_configuration':
undefined method'[]' for nil:NilClass (NoMethoError)
我的database.yml:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# 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:
<<: *default
database: db/test.sqlite3
production:
pool: 5
timeout: 5000
encoding: utf8
adapter: postgresql
host: <%= Rails.application.secrets[:database][:host]%>
database: <%= Rails.application.secrets[:database][:name]%>
username: <%= Rails.application.secrets[:database][:username]%>
password: <%= Rails.application.secrets[:database][:password]%>
感謝把我在良好的軌道,原因是缺少節點secrets.yml – scauglog 2015-02-25 15:46:45
所以..它歸結爲'添加'database'節'development'和'test'環境secrets.yml'。對? – 2016-03-21 16:12:10
我使用'ENV'變量數據庫連接,我已經把我的裏面設置'secrets.yml' ..但是運行時'軌s'並嘗試訪問Rails應用程序我得到這個錯誤'拒絕訪問用戶'root'@'localhost'(使用密碼:否)'..任何想法? – Lykos 2016-10-20 19:58:35