Forum: Ruby on Rails require_gem versus gem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F48118fe74b0c7f6fd82a0ee422fa34e?d=identicon&s=25 snacktime (Guest)
on 2007-03-04 05: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(File.open(File.dirname(__FILE__) +
'/config/database.yml'))
  ActiveRecord::Base.establish_connection(conf[environment])
end

connect('development')

Chris
Cee0292fffa691f1fb320d5400200e99?d=identicon&s=25 Marcel Molina Jr. (Guest)
on 2007-03-04 06: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
second
argument to specify a version constraint.

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

so if you just want to require activerecord and you don't care what
vesrion,
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
require
a gem, whether you want to specify a specific version constraint or not.

marcel
--
Marcel Molina Jr. <marcel@vernix.org>
F48118fe74b0c7f6fd82a0ee422fa34e?d=identicon&s=25 snacktime (Guest)
on 2007-03-04 06:12
(Received via mailing list)
Ah ok that makes sense, thanks for the explanation!

Chris
This topic is locked and can not be replied to.