# Updated 'gem'-unintialized constant ActiveRecord?

**URL:** <https://www.ruby-forum.com/t/updated-gem-unintialized-constant-activerecord/134297>\
**Category:** Rails\
**Created:** [April 9, 2008, 5:02pm UTC](https://www.ruby-forum.com/t/updated-gem-unintialized-constant-activerecord/134297 "2008-04-09T17:02:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 9, 2008, 5:02pm UTC](https://www.ruby-forum.com/t/updated-gem-unintialized-constant-activerecord/134297/1 "2008-04-09T17:02:57Z")

</div>

I would REALLY appreciate help with this. It’s driving me crazy, and  
I’ve accidentally messed up my app.

I was working on something that asked me to do a ‘gem update --system’.  
So I did. And then it broke my app.

First it was complaining about “require\_gem”. Okay, I hunted down that  
that’s obsolete, and I had to fix my old config/boot.rb to be the new  
config/boot.rb that rails today would generate, without obsolete code.  
Good enough. I did that, now my app gets further. But still won’t start  
up.

Huh, how can it not find ActiveRecord, what the heck?

Exiting  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active\_support/dependencies.rb:267:in  
`load_missing_constant': uninitialized constant ActiveRecord (NameError) from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:453:in`const\_missing’  
from  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active\_support/dependencies.rb:465:in  
`const_missing' from /usr/local/home/rochkind/U2/config/environment.rb:23 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 /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in`require’  
from  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active\_support/dependencies.rb:343:in  
`new_constants_in' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in`require’  
… 21 levels…  
from  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/server.rb:39  
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 ./script/server:3

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 9, 2008, 5:08pm UTC](https://www.ruby-forum.com/t/updated-gem-unintialized-constant-activerecord/134297/2 "2008-04-09T17:08:24Z")

</div>

> I was working on something that asked me to do a ‘gem update --system’.  
> So I did. And then it broke my app.

Why did you need to run the gem command?

Which platform are you on? Mac OS X? Some `gem` operations seem to  
break gem installs.

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 9, 2008, 5:10pm UTC](https://www.ruby-forum.com/t/updated-gem-unintialized-constant-activerecord/134297/3 "2008-04-09T17:10:41Z")

</div>

T K wrote:

> > I was working on something that asked me to do a ‘gem update --system’.  
> > So I did. And then it broke my app.
> 
> Why did you need to run the gem command?
> 
> Which platform are you on? Mac OS X? Some `gem` operations seem to  
> break gem installs.

I am on Linux, Red Hat.

I installed the ruby-prof gem, and then put the plugin into a little  
test app, to test it out. When I tried to start the test app, it told me  
I needed to update all my gems. So I (stupidly) did. Gem dependency  
issues are killing me here.

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 9, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/updated-gem-unintialized-constant-activerecord/134297/4 "2008-04-09T17:37:47Z")

</div>

Okay, I kind of sort of figured it out. But I still don’t understand.

I have this in my environment.rb:

ActiveRecord::Base.allow\_concurrency = true

[Let’s not get started on whether you can do this with Rails or not.  
Just trust me, you can if you’re careful. 🙂 ]

That used to work fine. After I updated gems, somehow ActiveRecord  
wasn’t defined yet in environment.rb (missing constant error)? I don’t  
get it.

If I add: require ‘active\_record’ to the top of my environment.rb, it  
works again—but I’m worried that manually requiring active\_record is  
going to get around Rails mechanisms of freezing versions and such. But  
also, I don’t understand why this is neccesary. Why isn’t ActiveRecord  
yet defined in environment.rb? Huh?

Jonathan R. wrote:

> T K wrote:
> 
> > > I was working on something that asked me to do a ‘gem update --system’.  
> > > So I did. And then it broke my app.

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 9, 2008, 6:15pm UTC](https://www.ruby-forum.com/t/updated-gem-unintialized-constant-activerecord/134297/5 "2008-04-09T18:15:15Z")

</div>

On 9 Apr 2008, at 16:37, Jonathan R. wrote:

> yet defined in environment.rb? Huh?

Where in environment.rb do you have that? ActiveRecord is only going  
to be defined once the initialisation process has loaded ActiveRecord.  
Any point after the Rails::Initializer.run … block should be fine.

Fred

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 9, 2008, 6:32pm UTC](https://www.ruby-forum.com/t/updated-gem-unintialized-constant-activerecord/134297/6 "2008-04-09T18:32:41Z")

</div>

So this blog post confirms that you can’t access ActiveRecord inside the  
config block.  
[http://toolmantim.com/article/2006/12/27/environments\_and\_the\_rails\_initialisation\_process](http://toolmantim.com/article/2006/12/27/environments_and_the_rails_initialisation_process)

The only mystery to me is why I _used_ to be able to in Rails 1.2.1  
before I updated my ‘gem’ gem! But okay, I’ll put it in a  
config.after\_initialize instead. For the record, and anyone else google  
searching on this problem.

Very weird, I still don’t understand why this used to work (and why  
there’s so much code on the web, and I think in the Agile Dev book, that  
assumes you can reference ActiveRecord in the config block!).

Thanks all for the help.

Jonathan

Jonathan R. wrote:

> Frederick C. wrote:
> 
> > On 9 Apr 2008, at 16:37, Jonathan R. wrote:
> > 
> > > yet defined in environment.rb? Huh?
> > 
> > Where in environment.rb do you have that? ActiveRecord is only going  
> > to be defined once the initialisation process has loaded ActiveRecord.  
> > Any point after the Rails::Initializer.run … block should be fine.
> > 
> > Fred
> 
> Thanks.
> 
> It’s inside the Rails::Initializer.run block. This used to work. For  
> some reason it stopped working when I updated my ‘gem’ gem (still using  
> the same version of Rails, 1.2.1). But is this not supposed to be done  
> this way? I find lots of sample code on the web that references  
> ActiveRecord inside the Rails::Initializer.run block?

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 10, 2008, 8:59am UTC](https://www.ruby-forum.com/t/updated-gem-unintialized-constant-activerecord/134297/7 "2008-04-10T08:59:34Z")

</div>

Um…

From what you say, you’ve ripped out your boot.rb file and replaced  
it, but not replaced the rest of your app!

If I were you, from my experience, I’d be rebuilding your app around a  
new rails generated skeleton.

Julian.

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)  
VIDEO #3 out NOW!  
[http://sensei.zenunit.com/](http://sensei.zenunit.com/)

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 10, 2008, 4:48pm UTC](https://www.ruby-forum.com/t/updated-gem-unintialized-constant-activerecord/134297/8 "2008-04-10T16:48:32Z")

</div>

Are there any guides anywhere to doing that? This is a very large app.  
I am a bit anxious over the idea of “rebuilding my app around a new  
rails generated skeleton”.

My issue is that this app was originally built for Rails 1.2.1, but I  
want to get it working on 1.2.6. It seems as if there were some  
significant changes to Rails skeleton files between these versions.

If I generate a new 1.2.6 app, and then take ALL the skeleton files and  
pop them into my app, should that work? It’s a lot easier for source  
control than taking the skeleton and trying to move all my own files  
into it (I want to go the other way instead).

Thanks for any advice. Rails backwards compatibility (or lack thereof)  
is turning into rather a nightmare for me!

Jonathan

Julian L. wrote:

> Um…
> 
> From what you say, you’ve ripped out your boot.rb file and replaced  
> it, but not replaced the rest of your app!
> 
> If I were you, from my experience, I’d be rebuilding your app around a  
> new rails generated skeleton.
> 
> Julian.
> 
> Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)  
> VIDEO #3 out NOW!  
> [http://sensei.zenunit.com/](http://sensei.zenunit.com/)

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 9, 2008, 6:25pm UTC](https://www.ruby-forum.com/t/updated-gem-unintialized-constant-activerecord/134297/9 "2008-04-09T18:25:22Z")

</div>

Frederick C. wrote:

> On 9 Apr 2008, at 16:37, Jonathan R. wrote:
> 
> > yet defined in environment.rb? Huh?
> 
> Where in environment.rb do you have that? ActiveRecord is only going  
> to be defined once the initialisation process has loaded ActiveRecord.  
> Any point after the Rails::Initializer.run … block should be fine.
> 
> Fred

Thanks.

It’s inside the Rails::Initializer.run block. This used to work. For  
some reason it stopped working when I updated my ‘gem’ gem (still using  
the same version of Rails, 1.2.1). But is this not supposed to be done  
this way? I find lots of sample code on the web that references  
ActiveRecord inside the Rails::Initializer.run block?
