Odd requirement behavior between two environments

I

Ian Whitney

I'm setting up a Ruby project on a new development machine and have run into
some trouble getting my unit tests to run. Can any one suggest what the
vital difference between these two machines might be, or what is causing the
error?

Esentially, my problem is that even though I have installed the ActiveRecord
gem, I am unable to use it in a script.

Old development machine where everything works:
Ruby 1.8.4
Gems 0.8.11
ActiveRecord gem installed 1.15.2

Results of IRB session on the old development machine

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require_gem 'activerecord'
=> true
irb(main):003:0> ActiveRecord
=> ActiveRecord

Ok, so that looks good. I can require the gem & then IRB knows what
ActiveRecord is. Great.

New development machine where this doesn't work
Ruby 1.8.6
Gems 0.9.4
ActiveRecord gem installed 1.15.3

Results of IRB session on the new development machine

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> gem 'activerecord'
=> true
irb(main):003:0> ActiveRecord
NameError: uninitialized constant ActiveRecord
from (irb):3

So, something is up. In line 2 I'm using the command newer command 'gem'
instead of the depreciated 'require_gem'. But I get the same result even if
I use the depreciated command.

Any ideas? Something I forgot to install on this new machine? Or some weird
configuration change I made on the old machine that I didn't copy over.


Thanks for any advice,

Ian
 
G

Gregory Brown

Ok, so that looks good. I can require the gem & then IRB knows what
ActiveRecord is. Great.

New development machine where this doesn't work
Ruby 1.8.6
Gems 0.9.4
ActiveRecord gem installed 1.15.3

Results of IRB session on the new development machine

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> gem 'activerecord'
=> true
irb(main):003:0> ActiveRecord
NameError: uninitialized constant ActiveRecord
from (irb):3

So, something is up. In line 2 I'm using the command newer command 'gem'
instead of the depreciated 'require_gem'. But I get the same result even if
I use the depreciated command.

Any ideas? Something I forgot to install on this new machine? Or some weird
configuration change I made on the old machine that I didn't copy over.

require_gem / gem are not the same as require. They're meant for
locking gems to specific versions or making sure they exist, not
loading libraries, e.g.

gem "ruport", "=1.0.1"

Also, with that in mind note that gem names don't always coincide with
library names, so you actually will need to do this:

require "rubygems"
require "active_record"

In earlier versions of RubyGems, it was possible for the require_gem
command to autoload libraries, this is no longer the case.

Hope that helps...

-greg
 
M

Martin DeMello

New development machine where this doesn't work
Ruby 1.8.6
Gems 0.9.4
ActiveRecord gem installed 1.15.3

Results of IRB session on the new development machine

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> gem 'activerecord'
=> true
irb(main):003:0> ActiveRecord
NameError: uninitialized constant ActiveRecord
from (irb):3

"gem" doesn't perform an implicit require; it simply modifies $: to
include the path to the gem.

irb(main):001:0> old = $:.dup
=> ["/usr/lib/ruby/site_ruby/1.8",
"/usr/lib/ruby/site_ruby/1.8/i686-linux", "/usr/lib/ruby/site_ruby",
"/usr/lib/ruby/1.8", "/usr/lib/ruby/1.8/i686-linux", "."]
irb(main):002:0> require 'rubygems'
=> true
irb(main):003:0> gem 'activerecord'
=> true
irb(main):004:0> $: - old
=> ["/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/bin",
"/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib",
"/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/bin",
"/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib"]
irb(main):005:0> require 'activerecord'
LoadError: no such file to load -- activerecord
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
from (irb):5
irb(main):006:0> require 'active_record' #sheesh
=> true
irb(main):007:0> ActiveRecord
=> ActiveRecord

martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top