2013-10-04 13 views
2

我正在通過一個基本的rails教程,當我嘗試使用「rails s」運行我的服務器時 我在我的localhost:3000瀏覽器中獲得了ActiveRecord :: ConnectionNotEstablished。確保database.yml文件具有正確的憑據

我在教程中告訴,以確保我的database.yml具有正確的憑據,但不知道 告訴如何做到這一點。我正在使用Postgresql。這是在我的databse.yml:

# SQLite version 3.x 
# gem install sqlite3 
# 
# Ensure the SQLite 3 gem is defined in your Gemfile 
# gem 'sqlite3' 
development: 
    adapter: postgresql 
    database: myrubyblog 
    username:postgres 
    password: theoffice 
    pool: 5 
    timeout: 5000 
    host: localhost 

# 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 
    database: myrubyblog 
    username:postgres 
    password: theoffice 
    pool: 5 
    timeout: 5000 
    host: localhost 

production: 
    adapter: postgresql 
    database: myrubyblog 
    username:postgres 
    password: theoffice 
    pool: 5 
    timeout: 5000 
    host: localhost 

謝謝!

+1

只是給我們你的'database.yml'文件不會有太大的幫助。 Habe你安裝了PostgreSQL嗎?你確保你的PostgreSQL服務器正在運行嗎?你可以通過運行'psql -U postgres postgres'直接連接到計算機上的PostgreSQL數據庫嗎? –

回答

1

嘗試刪除線:

pool: 5 
timeout: 5000 
host: localhost 

再次嘗試
啓動服務器。如果它仍然失敗。確保你已經正確安裝了psql

$ sudo -u postgres psql 
> CREATE ROLE "Blou91" PASSWORD 'secret' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN; 

如果你收到類似'Sucsses'的消息。更改database.yml,以:

common: &common 
    adapter: postgresql 
    username: "Blou91" 
    password: "secret" 

development: 
    <<: *common 
    database: myrubyblog_development 

test: 
    <<: *common 
    database: myrubyblog_test 

production: 
    <<: *common 
    database: myrubyblog_production 

然後你的Rails應用程序目錄下運行

$捆綁高管耙分貝:創建分貝:遷移