合并方法未在Rails控制台中定义

时间:2013-10-16 09:16:35

标签: ruby-on-rails

使用Rails 3.2。我有以下

# 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>'

指向merge中的application.rb方法。我在开发环境中运行rails c,运行正常。开发环境中的所有内容都可以正常工作,从读取app_config.yml到解析内容。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

尝试使用bundle exec rails c staging代替rails c RAILS_ENV=staging