2013-10-16 35 views
0

使用Rails 3.2。我有以下合併方法未在Rails控制檯中定義

# application.rb 
document = YAML.load(File.read(File.expand_path('../app_config.yml', __FILE__))) 
APP_CONFIG = document[Rails.env].merge(document['global']) 

# app_config.yml 
global: 
    site_name_lowercase: abc 

staging: 
    site_domain: 192.168.33.10 
    site_url: http://192.168.33.10 

development: 
    site_domain: abc.dev 
    site_url: http://abc.dev 

當我試圖運行rails c RAILS_ENV=staging,我有以下幾點:

/home/deployer/abc/releases/20131015193830/config/application.rb:9:in `<top (required)>': undefined method `merge' for nil:NilClass (NoMethodError) 
    from /home/deployer/abc/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:39:in `require' 
    from /home/deployer/abc/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:39:in `<top (required)>' 
    from script/rails:6:in `require' 
    from script/rails:6:in `<main>' 

它指向application.rbmerge方法。我在開發環境中運行了rails c,工作正常。從開發環境中讀取app_config.yml到解析其中的內容,開發環境中的所有內容都可以正常工作。我怎樣才能解決這個問題?

+0

在加載YAML文件並查看它說的內容之前,您可以在'application.rb'中添加'puts Rails.env'嗎? – matkins

+0

正如'abort(Rails.env.inspect)'?它輸出'「RAILS_ENV = staging」'。 – Victor

+0

它適用於我。您的暫存服務器上的app_config.yml可能不同嗎? – matkins

回答

1

嘗試bundle exec rails c staging而不是rails c RAILS_ENV=staging

+0

已經嘗試過'bundle exec RAILS_ENV = staging rails c',它不起作用。 – Victor

+0

'RAILS_ENV =暫存bundle exec rails c'如何? – matkins

+0

其實,我覺得'bundle exec rails c staging'是Rails 3的標準。 – matkins

相關問題