valibuk.net

A place for opinions and notes of a valibuk.

require_gem ‘activerecord’

Tagged with: — ondrej at 1:05 am on Tuesday, March 11, 2008

A Ruby application that uses the ActiveRecord library (not a Ruby on Rails application) stopped working for me after an update of Ruby. The error message was:

  1. undefined method `require_gem’ for main:Object (NoMethodError)

The corresponding source code was:

  1.  

I checked the documentation and I realised that require_gem is obsolete and gem should be used instead:

  1.  

But I got another error (the name of the class is Person):

  1. uninitialized constant Person::ActiveRecord (NameError)

Then I checked the documentation again (it helps usually :) and I found out that gem only adds a path of a gem, so it is still necessary to add the require part. But there is a tiny catch – although the gem name is activerecord, the main file name is active_record.rb, so you need to specify the active_record value:

  1.  

Enjoy :)

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • DZone
  • Digg
  • Reddit
  • Technorati
  • Furl
  • NewsVine
  • Slashdot
  • Ma.gnolia
  • StumbleUpon

9 Comments »

Comment by dev

April 1, 2008 @ 3:48 am

Best answer to annoying problem

Comment by Tom

April 16, 2008 @ 12:32 am

Thanks, You just got me on the road quickly with this, since
I had just falled in the same hole, … thanks!

Comment by H

April 21, 2008 @ 8:21 am

Thank you! I had this issue while following an example in my Ruby on Rails book and this solved it quickly!

Comment by RRob

May 16, 2008 @ 2:58 pm

Thanks, a bunch

Comment by Magirus

August 14, 2008 @ 6:15 pm

I hate this!
Programmers are so lazy.

The right thing would be to give a warning when using require_gem that it is outdated and how you should use it now.

And why the activerecord has an underscore it one case and not in the other is another man made trap by someone that was thinking too short and leads to madness…

Sad. Really sad.

Comment by ondrej

August 18, 2008 @ 11:19 pm

yeah, we are so lazy :)

Comment by john

August 24, 2008 @ 12:34 am

thank you thank you thank you – you rescued my evening!

Comment by Charlie

January 6, 2010 @ 1:34 pm

Thanks dude! Annoying stuff…

Comment by ondrej

January 7, 2010 @ 12:34 am

you are welcome :)

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Comment Preview


commercial break :)

Make an account on slicehost.com -- a really good hosting where you have your own virtual machine. I installed Gentoo there = I like it very much ;)