2010-09-06 36 views
14

我的應用程序在生產中非常完美 - 至少是其網站的一部分。只有當我進入我的VPS並執行「rails c RAILS_ENV = production」時,纔會彈出問題。控制檯在開發模式下工作正常。無法打開rails控制檯:生產數據庫未配置,establish_connection引發ActiveRecord :: AdapterNotSpecified

我以前有過這個問題(或者至少有一個看起來像這樣),並且通過向database.yml添加「reconnect:true」來修復它 - 但這次沒有修復它。下面是錯誤輸出的開始:

/home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:62:in `establish_connection': RAILS_ENV=production database is not configured (ActiveRecord::AdapterNotSpecified) 
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection' 
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/railtie.rb:59:in `block (2 levels) in <class:Railtie>' 
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval' 
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook' 
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/lazy_load_hooks.rb:26:in `on_load' 
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/railtie.rb:57:in `block in <class:Railtie>' 
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `instance_exec' 
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `run' 
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/initializable.rb:50:in `block in run_initializers' 

而對於我的生產數據庫設置:

production: 
    adapter: mysql 
    encoding: utf8 
    database: tour_production 
    pool: 5 
    username: [user] 
    password: [password] 
    socket: /var/run/mysqld/mysqld.sock 
    reconnect: true 

我不能讓我的周圍爲什麼它的工作原理,通過乘客的心意,但與控制檯沒有運氣。無論如何,我使用Rails 3,Ruby 1.9.2,Passenger和Nginx。

我一直在做一些小東西,通過亞軍,這是煩人的。我想弄清楚這個問題。所以謝謝一幫人的幫助。

回答

48

當您使用控制檯時,您將環境指定爲第一個參數而不是環境變量。所以:

ruby script/console production 

會加載生產環境。

您的錯誤消息是因爲它正在尋找環境RAILS_ENV=production而不僅僅是production

+1

嗯,這樣做。看起來每個命令都有不同的方式來聲明rails環境。感謝大家的快速回答。 – Nathan 2010-09-06 21:08:13

17

@Shadwell是正確的,但如果你是一個一致的語法後,您可以像今年年初設定RAILS_ENV

RAILS_ENV=production rails console 
42

最新的Rails 3這樣的方式很簡單:

bundle exec rails console production 
+6

實際上,它更像是:bundle exec軌道控制檯製作 – Dogweather 2012-01-26 06:54:23

+0

bundle exec軌道控制檯製作作品 – Hendrik 2012-04-22 11:37:51

+0

您的方法更好。更新了我的答案。 – 2012-04-23 17:36:12

相關問題