无法加载此类文件 - activerecord(LoadError)

时间:2015-02-20 09:45:25

标签: ruby-on-rails ruby ruby-on-rails-3 activerecord

我尝试将一个非常古老的应用程序从Rails 2.3.12升级到Rails 3.0.0(作为将其转换为Rails 4的起点)。我已经慢慢地通过删除旧宝石等来修复自升级以来已经破坏的任何东西。

我遇到了一个我似乎无法确定或修复的问题。

我正在运行Rails3,Ruby1.9.3

当我尝试运行rails服务器时,出现以下错误:

    => Booting WEBrick
=> Rails 3.0.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require': cannot load such file -- activerecord (LoadError)
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `block in require'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `block in load_dependency'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in `new_constants_in'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from /home/camillavk/Documents/Work/Saild/saild/vendor/plugins/acts_as_commentable/lib/commentable_methods.rb:1:in `<top (required)>'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `block in require'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `block in load_dependency'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in `new_constants_in'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from /home/camillavk/Documents/Work/Saild/saild/vendor/plugins/acts_as_commentable/lib/acts_as_commentable.rb:1:in `<top (required)>'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `block in require'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `block in load_dependency'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in `new_constants_in'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from /home/camillavk/Documents/Work/Saild/saild/vendor/plugins/acts_as_commentable/rails/init.rb:1:in `block in <class:Plugin>'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/plugin.rb:81:in `eval'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/plugin.rb:81:in `block in <class:Plugin>'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `instance_exec'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `run'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/initializable.rb:50:in `block in run_initializers'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/initializable.rb:49:in `each'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/initializable.rb:49:in `run_initializers'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/application.rb:134:in `initialize!'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/application.rb:77:in `method_missing'
        from /home/camillavk/Documents/Work/Saild/saild/config/environment.rb:7:in `<top (required)>'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `block in require'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `block in load_dependency'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in `new_constants_in'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from /home/camillavk/Documents/Work/Saild/saild/config.ru:3:in `block in <main>'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rack-1.2.8/lib/rack/builder.rb:46:in `instance_eval'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rack-1.2.8/lib/rack/builder.rb:46:in `initialize'
        from /home/camillavk/Documents/Work/Saild/saild/config.ru:1:in `new'
        from /home/camillavk/Documents/Work/Saild/saild/config.ru:1:in `<main>'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rack-1.2.8/lib/rack/builder.rb:35:in `eval'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rack-1.2.8/lib/rack/builder.rb:35:in `parse_file'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rack-1.2.8/lib/rack/server.rb:162:in `app'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rack-1.2.8/lib/rack/server.rb:253:in `wrapped_app'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rack-1.2.8/lib/rack/server.rb:204:in `start'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/commands/server.rb:65:in `start'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/commands.rb:30:in `block in <top (required)>'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/commands.rb:27:in `tap'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.0/lib/rails/commands.rb:27:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

My Gemfile如下所示:

source 'https://rubygems.org'

gem "rails", "3.0.0"

gem "airbrake"
gem "aws-s3"
gem "bj"
gem "bundler", "~> 1.0.0"
gem "calendar_date_select", "1.15"
gem "cancan", "1.2.0"
gem "carmen"
gem 'comma', '0.4.1'
gem 'exifr'
# factory_girl 1.2.4 wasn't working with Rails 3 - consider an upgrade to factory_girl_rails?
# gem "factory_girl", "1.2.4"
gem 'fastercsv'
gem "geokit"
gem "haml"
gem "hpricot"
gem 'hoptoad_notifier'
gem "jrails"
gem "libxml-ruby", "2.4.0"
gem "memcached", "~> 1.8.0"
#memcached no longer works?
gem 'dalli'
# Not sure why we have this if we're using SQLite3
gem "mysql2", "~> 0.2.6"
#TODO: changed by almazom
gem "rake", "0.8.4"
gem 'recurly'
gem "rdoc"
gem "rmagick"
gem "rspreedly"
gem "rubyzip"
gem 'sass'
#need to use simplecov when upgrading to ruby 2 as rcov doesn't work
gem "simplecov"
gem 'sqlite3'
# tmail no longer included in rails 3?
gem 'tmail'
gem "will_paginate", "2.3.16"
gem 'yaml_db'

group :development, :test do
  gem 'test-unit', '1.2.3'
  gem 'rspec', '1.3.2'
  gem 'rspec-rails', '~> 1.3.4'
end

group :test do
  gem 'capybara', '0.3.5'
  gem 'cucumber', '1.1.2'
  gem 'cucumber-rails', :git => "git://github.com/RKelln/cucumber-rails.git", :branch => "0.3.2-capybara-fix"
  gem 'database_cleaner'
end

升级到Rails 3之前是否有其他人遇到此问题?我无法在Google上找到任何关于它的内容......

或者有人建议我如何找到/解决问题吗?

非常感谢提前!

1 个答案:

答案 0 :(得分:2)

让我们来看看你的堆栈跟踪。堆栈跟踪从上到下读取。如果你有函数A调用函数B调用函数C,那么发生错误,堆栈跟踪显示

C
B
A

我们可以看到第一行全部来自Rails本身:

/home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require': cannot load such file -- activerecord (LoadError)
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `block in require'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `block in load_dependency'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in `new_constants_in'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
        from /home/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'

由于Rails本身通常不太可能是罪魁祸首,我们会寻找来自其他地方的第一行 - 您自己的代码或第三方库。

下一行就是:

        from /home/camillavk/Documents/Work/Saild/saild/vendor/plugins/acts_as_commentable/lib/commentable_methods.rb:1:in `<top (required)>'

我们在vendor/plugins看到它的代码,使其成为一个旧的Rails 2.3风格的插件。它们在Rails 3中被弃用,并完全停止在Rails 4中工作。它们被替换为通过Gemfile和Bundler添加的“Gem插件”,而不是vendor/plugins

所以acts_as_commentable是罪魁祸首的好候选人。 Github project页面显示了一个特别适用于Rails 3的版本,因此删除旧插件并将其替换为Gem可以很好地解决此问题。