Forum: Ruby on Rails require_gem versus gem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
snacktime (Guest)
on 2007-03-04 06:56
(Received via mailing list)
Trying to figure out why require_gem works and gem doesn't.  using
just gem, I get uninitialized constant ActiveRecord (NameError).  Use
require_gem and it works, but tells me that require_gem is obsolete.

require 'rubygems'
gem 'activerecord'

def connect(environment)
  conf = YAML::load( +


Marcel Molina Jr. (Guest)
on 2007-03-04 07:04
(Received via mailing list)
On Sat, Mar 03, 2007 at 08:55:40PM -0800, snacktime wrote:
> end
> connect('development')

require_gem was a wrapper around require that accepted an optional
argument to specify a version constraint.

the new gem method is not a wrapper around require. it simply registers
version constraint on the named gem. when you subsequently call require,
version constraint is verified.

so if you just want to require activerecord and you don't care what
just do require 'activerecord'. otherwise, use the gem method first to
specify which versions.

of course, you still have to require 'rubygems' first if you want to
a gem, whether you want to specify a specific version constraint or not.

Marcel Molina Jr. <removed_email_address@domain.invalid>
snacktime (Guest)
on 2007-03-04 07:12
(Received via mailing list)
Ah ok that makes sense, thanks for the explanation!

This topic is locked and can not be replied to.