【问题标题】:Why am I getting an error when requiring this gem in environment.rb?为什么在 environment.rb 中需要此 gem 时出现错误?
【发布时间】:2010-03-05 18:48:36
【问题描述】:

我按照here 的步骤安装了composite_primary_keys gem。当我尝试通过

在文件的最底部(在“结束”之后)要求 environment.rb 中的 gem 时
require 'composite_primary_keys'

我在启动服务器时得到这个

"69125"
=> Booting Mongrel
=> Rails 2.3.4 application starting on http://127.0.0.1:3002
/Library/Ruby/Site/1.8/rubygems.rb:270:in `activate': You have a nil object when you didn't expect it! (NoMethodError)
You might have expected an instance of Array.
The error occurred while evaluating nil.map
 from /Library/Ruby/Site/1.8/rubygems.rb:296:in `activate'
 from /Library/Ruby/Site/1.8/rubygems.rb:295:in `each'
 from /Library/Ruby/Site/1.8/rubygems.rb:295:in `activate'
 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:35:in `require'
 from /path/to/www/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
 from /path/to/www/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
 from /path/to/www/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
 from /path/to/www/config/environment.rb:54
 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
 from /path/to/www/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
 from /path/to/www/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
 from /path/to/www/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
 from /path/to/www/vendor/rails/railties/lib/commands/server.rb:84
 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
 from ./script/server:3
 from -e:2:in `load'
 from -e:2

知道为什么会这样吗?

【问题讨论】:

  • config/environment.rb 的第 54 行是什么?
  • 需要'composite_primary_keys'

标签: ruby-on-rails rubygems


【解决方案1】:

试着把它放在你的 environment.rb 中,像这样:

Rails::Initializer.run do |config|

  config.gem 'composite_primary_keys'

end

【讨论】:

  • 嗯,我认为我的导轨安装搞砸了。现在我什至无法在没有任何更改的情况下启动服务器。我正在更新 gem,我们会看看会发生什么。
  • 现在我在运行脚本/服务器时得到这个:Library/Ruby/Site/1.8/rubygems.rb:220:in activate': undefined method map' for nil:NilClass (NoMethodError)
  • 呃,你没有删除 environment.rb 中的所有内容,是吗?我只是给了你一个空白的例子,但是还有一些其他的东西适合那里,比如时区设置..请编辑你的原始帖子,并从启动服务器开始使用完整的错误日志。
  • 好的,通过还原和修补更改来解决此问题。现在我在使用 config.gem 包含 gem 时得到了这个:/Library/Ruby/Site/1.8/rubygems.rb:220:in activate': undefined method map' for nil:NilClass (NoMethodError)
  • 您能向我们展示您的整个 environment.rb(减去 cmets)吗?另外,您是否在开发模式下运行(默认)?
猜你喜欢
  • 1970-01-01
  • 2011-07-17
  • 2022-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-08
  • 1970-01-01
  • 2012-12-15
相关资源
最近更新 更多