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
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.