为什么在environment.rb中需要这个gem时会出错? [英] Why am I getting an error when requiring this gem in environment.rb?

查看:148
本文介绍了为什么在environment.rb中需要这个gem时会出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循这里的步骤并安装了composite_primary_keys gem。当我试图通过

I followed the steps here and installed the composite_primary_keys gem. When I try to require the gem in environment.rb at the very bottom of the file (after 'end') via

require 'composite_primary_keys'

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

I get this when starting the server

"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

发生什么?

推荐答案

试试把它放在你的environment.rb中:

Try putting it in your environment.rb like this:

Rails::Initializer.run do |config|

  config.gem 'composite_primary_keys'

end

这篇关于为什么在environment.rb中需要这个gem时会出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆