2013-09-28 13 views
6

我在做Ruby on Rails Tutorial.前三章使用SQLite,但後來它建議在開發中使用PostgreSQL以便更容易部署Heroku。在編輯我的database.ymlGemfile以使用pg代替sqlite3後,它似乎能夠工作 - 除了使用Rake運行測試時。它彈出一個AdapterNotSpecified錯誤。Rails/ActiveRecord - AdapterNotSpecified,即使它是

C:/Ruby/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/lib/active_record/ connection_adapters/connection_specification.rb:52:in resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecif ied)

的database.yml中指定一個適配器,就像這樣:

development: 
    adapter: postgresql 
    host: localhost 
    username: nekkoru 
    password: derpderp 
    database: development 
    encoding: UTF8 

這是怎麼回事?我在Windows 7 x64,Ruby 1.9.3,Rails 4.0.0,PostgreSQL 9.3.0.1。

回答

12

您沒有爲測試環境定義數據庫。你database.yml文件應該是這樣:

development: 
    adapter: postgresql 
    host: localhost 
    username: nekkoru 
    password: derpderp 
    database: development 
    encoding: UTF8 

test: 
    adapter: postgresql 
    host: localhost 
    username: nekkoru 
    password: derpderp 
    database: test  # or whatever the name is 
    encoding: UTF8 
+0

現在我覺得愚蠢。這當然有效。謝謝:) – Nekkoru

+0

這非常有幫助。我沒有意識到rake任務會自動完成開發/測試。 –

6

縮進對我來說是罪魁禍首。

的Rails似乎有從YML文件中讀取數據庫類型(開發或生產)和DB設置(適配器,主機,用戶名,等等等等),嚴格的方式。

但當然ActiveRecord的錯誤味精是矯枉過正..這使得它看起來像我錯過了一個寶石

+2

謝謝。你真的救了我的命。 – inquisitive