简体   繁体   中英

cannot load such file — activerecord (LoadError)

I'm trying to upgrade a very old app from Rails 2.3.12 to Rails 3.0.0 (as a starting point to getting it to Rails 4). I've been slowly going through and fixing anything that has broken since the upgrade by removing old gems etc.

I've got stuck on a problem that I can't seem to pin point or fix.

I'm running Rails3, Ruby1.9.3

When I try to run the rails server I get the following error:

    => 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 looks like this:

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

Has anyone else encountered this problem before when upgrading to Rails 3? I can't find anything on Google about it....

Or does anyone have a suggestion on how I can find/fix the issue?

Many thanks in advance!

Let's take a look at your stack trace. Stack traces are read top to bottom. If you have function A calling function B calling function C, where an error happens, the stack trace shows

C
B
A

We can see that the first lines all come from Rails itself:

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

Since it's usually unlikely that Rails itself is the culprit, we look for the first line that comes from some place else — either your own code, or a third-party library.

The next line is just that:

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

We see that it's code at vendor/plugins , making it an old, Rails 2.3-style plugin. They were deprecated in Rails 3 , and completely stopped working in Rails 4. They were replaced by "Gem plugins" that are added through your Gemfile and Bundler, instead of vendor/plugins .

So acts_as_commentable is a good candidate as the culprit. The Github project page shows a version especially for Rails 3, so removing the old plugin and replacing it with that Gem gives you a good shot at fixing this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM