require_gem ‘activerecord’
A Ruby application that uses the ActiveRecord library (not a Ruby on Rails application) stopped working for me after an update of Ruby. The error message was:
-
undefined method `require_gem’ for main:Object (NoMethodError)
The corresponding source code was:
-
require ‘rubygems’
-
require_gem ‘activerecord’
I checked the documentation and I realised that require_gem is obsolete and gem should be used instead:
-
require ‘rubygems’
-
gem ‘activerecord’
But I got another error (the name of the class is Person):
-
uninitialized constant Person::ActiveRecord (NameError)
Then I checked the documentation again (it helps usually :) and I found out that gem only adds a path of a gem, so it is still necessary to add the require part. But there is a tiny catch - although the gem name is activerecord, the main file name is active_record.rb, so you need to specify the active_record value:
-
require ‘rubygems’
-
gem ‘activerecord’
-
require ‘active_record’
Enjoy :)










