使用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.rb
的merge
方法。我在開發環境中運行了rails c
,工作正常。從開發環境中讀取app_config.yml
到解析其中的內容,開發環境中的所有內容都可以正常工作。我怎樣才能解決這個問題?
在加載YAML文件並查看它說的內容之前,您可以在'application.rb'中添加'puts Rails.env'嗎? – matkins
正如'abort(Rails.env.inspect)'?它輸出'「RAILS_ENV = staging」'。 – Victor
它適用於我。您的暫存服務器上的app_config.yml可能不同嗎? – matkins