Undefined method `gem' for main:Object after rake rails:freeze:gems

Help! I’m kinda stuck…I’m pretty sure that I somehow need to
‘freeze’ RubyGem itself (aka gem) although given the error below, I’m
not sure. I can’t downgrade & freeze to the rails version on the host
since my app depends on some Rails2x stuff.

If indeed I need to ‘freeze’ gem’, is there standard way to do this?
or any idea as to what exactly I’d need to do (i.e. how do I get my
app to “see” the correct ‘gem’ command).

The reason I ask is because I’m getting this error message spewing
from my app on a shared host:
myHostDir/httpdocs/newsite/app/vendor/rails/activerecord/lib/…/…/
activesupport/lib/active_support/vendor.rb:5:
undefined method gem' for main:Object (NoMethodError) from /httpdocs/newsite/app/vendor/rails/activerecord/lib/../../ activesupport/lib/active_support.rb:26:inrequire’
from /httpdocs/newsite/app/vendor/rails/activerecord/lib/…/…/
activesupport/lib/active_support.rb:26
from /httpdocs/newsite/app/vendor/rails/activerecord/lib/
active_record.rb:31:in require' from /httpdocs/newsite/app/vendor/rails/activerecord/lib/ active_record.rb:31 from ./../config/../vendor/rails/railties/lib/initializer.rb:156:inrequire’
from ./…/config/…/vendor/rails/railties/lib/initializer.rb:156:in
require_frameworks' from ./../config/../vendor/rails/railties/lib/initializer.rb:156:ineach’
from ./…/config/…/vendor/rails/railties/lib/initializer.rb:156:in
require_frameworks' from ./../config/../vendor/rails/railties/lib/initializer.rb:88:inprocess’
from ./…/config/…/vendor/rails/railties/lib/initializer.rb:49:in
send' from ./../config/../vendor/rails/railties/lib/initializer.rb:49:inrun’
from ./…/config/environment.rb:13
from dispatch.cgi:3:in `require’
from dispatch.cgi:3
[client ] Premature end of script headers: /
httpdocs/newsite/app/public/dispatch.cgi

Of course the app gives:
Application error
Rails application failed to start properly"

The app is running fine on my development box with InstantRails 2.x
specifically:
rails: 2.0.2
gem: 1.0.1
ruby: 1.8.6 patchlevel 111
Unfortunately my host is running rails 1.1.2, and I don’t have shell
access so this is all the info I’ve got there:
rails: 1.1.2
gem: ???
ruby: 1.8.4

Or am I totally stuck & have to see if they’ll upgrade ruby on the
host?
Thanks,
Dale

I should mention that the development box is winXP with instantRails
2.

On 29 Feb 2008, at 15:50, Dale wrote:

Help! I’m kinda stuck…I’m pretty sure that I somehow need to
‘freeze’ RubyGem itself (aka gem) although given the error below, I’m
not sure. I can’t downgrade & freeze to the rails version on the host
since my app depends on some Rails2x stuff.

If indeed I need to ‘freeze’ gem’, is there standard way to do this?
or any idea as to what exactly I’d need to do (i.e. how do I get my
app to “see” the correct ‘gem’ command).

That could be the case: the require_gem method was replaced by gem in
newer versions of ruby gems. (ie the problem here isn’t the gem
command itself but the gem library.
You should be able to convince ruby to load the gem library from
somewhere else (either via the -I option or via fiddling with $LOAD_PATH

Fred

I tried a bunch of things…none of which worked. Fortunately the
hosting provider was willing to upgrade to the latest ruby & gems.
Which works great now! The downside is I’ll never probably know quite
how to ‘freeze’ the gem command into the application.

For the curious, here’s what I tried:
ran the follwing in my app/vendor/gems directory:
gem unpack rubygems-update
Then re-transferred the entire app to the host, trying several things
(none of these worked):

  • modifying environment.rb to include (also tried without the /bin at
    the end)
    ENV[‘GEM_PATH’] = File.dirname(FILE)+’…/vendor/gems/rubygems-
    update-1.0.1/bin’

  • modifying the config.load_path in the environment.rb trying each of
    the following with & without /bin)

config.load_paths += %W( #{RAILS_ROOT}/vendor/gems/rubygems-

update-1.0.1/bin )

config.load_paths += "#{File.dirname(FILE)}/…/vendor/gems/

rubygems-update-1.0.1/bin"

  • modifying the dispatch.cgi “shebang” to:
    #!/usr/bin/ruby -I …/vendor/gems/rubygems-update-1.0.1/bin

  • I tried the gemsonrails gem, but couldn’t get it to work with my
    custom rake deploy (all deploy does is copy app files to a directory I
    use to then ftp to the host)

So in summary, what worked…upgrade ruby & the gems on the server.
-Dale

On Feb 29, 10:18 am, Frederick C. [email protected]
wrote:

That could be the case: the require_gem method was replaced by gem in
newer versions of ruby gems. (ie the problem here isn’t the gem
command itself but the gem library.
You should be able to convince ruby to load the gem library from
somewhere else (either via the -I option or via fiddling with $LOAD_PATH

Fred

Fred, so if I understand this correctly I need to find my development
box’s gem path and bulk upload that to the server in something like:
myHostDir/gems

Then modify my dispatch.* stuff to use “/usr/bin/ruby -I myHostDir/
gems”

Have I got that right?

Thanks again,
Dale

In case anyone ends up back here…my server reverted to the old rails
gems. So I had to solve this problem for ‘real’
Here’s a link to how I did it:
http://www.godale.org/blog/2008/04/freezing-rubygems-on-shared-server.html

-Dale

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs