没有这样的文件来加载active_record / associations / has_and_belongs_to_many_association

时间:2012-06-13 20:57:19

标签: ruby ruby-on-rails-3

我在我的Gemfile中添加了composite_primary_keys gem。在本地环境下运行正常,但在centos机器上它会出现以下错误。在这两种环境下,Ruby版本为1.9.2p290,rubygems版本为1.3.7。有谁知道为什么会这样?

bundle exec rake db:create --trace

no such file to load -- active_record/associations/has_and_belongs_to_many_association
/var/tmp/jenkins/gem_cache/myapp/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
/var/tmp/jenkins/gem_cache/myapp/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `block in require'
/var/tmp/jenkins/gem_cache/myapp/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `block in load_dependency'
/var/tmp/jenkins/gem_cache/myapp/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:640:in `new_constants_in'
/var/tmp/jenkins/gem_cache/myapp/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency'
/var/tmp/jenkins/gem_cache/myapp/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
/var/tmp/jenkins/gem_cache/myapp/gems/composite_primary_keys-4.1.2/lib/composite_primary_keys.rb:40:in `<top (required)>'
/opt/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in `require'
/opt/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/opt/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in `each'
/opt/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in `block in require'
/opt/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in `each'
/opt/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in `require'
/opt/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler.rb:122:in `require'

3 个答案:

答案 0 :(得分:1)

尝试在Active Record 4.1.0中使用composite_primary_keys gem时可能会发生同样的错误:

.../vendor/cache/ruby/1.9.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require': cannot load such file -- active_record/associations/has_and_belongs_to_many_association (LoadError)
  from .../vendor/cache/ruby/1.9.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `block in require'
  from .../vendor/cache/ruby/1.9.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
  ...

这是因为当前发布的composite_primary_keys(截至2014年4月17日的版本6.0.1)并未包含对Active Record 4.1.0的支持,显然已删除了相关文件。

但问题已在the ar_4.1.x branch of the gem's source code中修复。如果您的项目使用Bundler,则解决方案是编辑其Gemfile并替换行

gem 'composite_primary_keys'

gem 'composite_primary_keys', {
  :git => 'git://github.com/composite-primary-keys/composite_primary_keys.git',
  :branch => 'ar_4.1.x'
}

然后从项目的根文件夹中运行bundle install

答案 1 :(得分:0)

清理jenkins机器上的共享gems列表解决了这个问题。

答案 2 :(得分:0)

更新您的Gemfile: gem 'composite_primary_keys', '~> 7.0'