2017-07-11 76 views
0

我一直在試圖設置我的新的MacBook Pro(Sierra 10.12.5)使用Rails - 我已經安裝了Ruby 2.4.1,Rails 5.0.2和PSQL 9.6.3 。我在安裝pg 0.20.0時遇到了麻煩,但我可以通過Homebrew來完成。設置用於Rails的PSQL

現在我無法通過本地主機運行任何我MVCS的,因爲我說:

PG Connection Bad - fe_sendauth: no password supplied - 
    # connected server's characteristics. 
    def connect 
     @connection = PGconn.connect(@connection_parameters) 
     configure_connection 
    rescue ::PG::Error => error 
     if error.message.include?("does not exist") 

我認爲這是用psql連接到服務器的問題,但我真的不確定它會是什麼或接下來要做什麼。

我真的很感激任何指針,謝謝。

+0

你配置好database.yml嗎? –

+0

您需要在數據庫yml文件中設置配置。看起來你可能已經設定了相同但不正確。 –

回答

1

請確保您有config/database.yml表現爲以下內容

development: 
    adapter: postgresql 
    encoding: utf8 
    reconnect: false 
    database: development_db 
    pool: 5 
    username: postgres # Replace this with correct username 
    password: db_password # Replace this with correct password 
    host: localhost 

你可以利用這裏的環境變量

username: <%= ENV['DB_USER'] %> 
password: <%= ENV['DB_PASS'] %> 

您需要首先設置在外殼

$ export DB_USER=postgres 
$ export DB_PASS=password 
+0

同意,並且它將廣泛查看幫助管理這些環境變量的寶石。 –

+0

是的,dotenv就是這樣一個gem https://github.com/bkeepers/dotenv –

+0

我猜想當我設置MVC時,用戶名和密碼是自動配置的,因爲我不記得這件事。 – Robert