有人可以闡述爲什麼應用程序在生產與開發模式下表現不同。我已檢查並重新檢查config/database.yml
並確保用戶名和密碼正確。事實上,在寫這篇文章的時候,我已經設定了開發和生產數據庫都是一樣的。然而,當我在生產環境中運行服務器時,Mysql2抱怨訪問被拒絕,但在開發環境中工作正常。Rails應用程序在開發與生產中的表現有所不同
運行時發生同樣的事rails c production
vs rails c development
,開發中沒有錯誤,但在生產中沒有發生Mysql2訪問錯誤。
生產模式
$ rails s -e production
=> Booting WEBrick
=> Rails 4.0.2 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-03-19 18:20:22] INFO WEBrick 1.3.1
[2014-03-19 18:20:22] INFO ruby 2.1.0 (2013-12-25) [x86_64-freebsd10.0]
[2014-03-19 18:20:22] INFO WEBrick::HTTPServer#start: pid=10800 port=3000
I, [2014-03-19T18:20:30.569167 #10800] INFO -- : Started GET "/" for 192.168.1.102 at 2014-03-19 18:20:30 +0200
F, [2014-03-19T18:20:30.709229 #10800] FATAL -- :
Mysql2::Error (Access denied for user 'root'@'localhost' (using password: YES)):
發展模式
$ rails s -e development
=> Booting WEBrick
=> Rails 4.0.2 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-03-19 18:22:53] INFO WEBrick 1.3.1
[2014-03-19 18:22:53] INFO ruby 2.1.0 (2013-12-25) [x86_64-freebsd10.0]
[2014-03-19 18:22:53] INFO WEBrick::HTTPServer#start: pid=10898 port=3000
Started GET "/" for 192.168.1.102 at 2014-03-19 18:23:03 +0200
Processing by Rails::WelcomeController#index as HTML
Rendered /home/user/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/templates/rails/welcome/index.html.erb (2.3ms)
Completed 200 OK in 24ms (Views: 11.6ms | ActiveRecord: 0.0ms)
這裏是我的config/database.yml的。
development:
adapter: mysql2
encoding: utf8
database: amo
pool: 5
username: root
password: mypass
host: localhost
production:
adapter: mysql2
encoding: utf8
database: amo
pool: 5
username: root
password: mypass
host: localhost
O/S:10.0 FreeBSD的64位
紅寶石:2.1.0(安裝在使用Rbenv)
滑軌:4.0.2
顯示你的'config/database.yml'。 –
當然。正在編輯我的帖子以添加它並看到您的評論。完成:) –
你有沒有解決你的問題? –