# Very simple code throwing "uninitialized constant" error

**URL:** <https://www.ruby-forum.com/t/very-simple-code-throwing-uninitialized-constant-error/117243>\
**Category:** Rails\
**Created:** [October 15, 2007, 8:11am UTC](https://www.ruby-forum.com/t/very-simple-code-throwing-uninitialized-constant-error/117243 "2007-10-15T08:11:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 15, 2007, 8:11am UTC](https://www.ruby-forum.com/t/very-simple-code-throwing-uninitialized-constant-error/117243/1 "2007-10-15T08:11:09Z")

</div>

This code works on an older version of Ruby and Rails but not with  
Ruby 1.8.6 and Rails 1.2.5. The code is so simple that I can’t figure  
out where the problem is.

profile\_controller.rb

class ProfileController \< ApplicationController  
def show  
@profile = Profile.find\_by\_school\_id(params[:id])  
end  
end

* * *

profile.rb

class Profile \< ActiveRecord::Base  
belongs\_to :school  
belongs\_to :profile\_type  
translates :text #\<— I’m using the Globalize plugin  
end

* * *

[http://localhost:3000/en/profile/show/51](http://localhost:3000/en/profile/show/51) throws:

NameError in ProfileController#show

uninitialized constant Profile

RAILS\_ROOT: script/…/config/…

vendor/rails/activesupport/lib/active\_support/dependencies.rb:100:in  
`const_missing' vendor/rails/activesupport/lib/active_support/dependencies.rb:131:in `const\_missing’  
vendor/rails/activesupport/lib/active\_support/dependencies.rb:133:in  
`send' vendor/rails/activesupport/lib/active_support/dependencies.rb:133:in `const\_missing’  
app/controllers/profile\_controller.rb:4:in `show’

* * *

If I change the query to @profile = Foobar.find(:first, :conditions =\>  
[“school\_id = ?”, params[:id]])

I get a similar error, but it also adds:

This error occured while loading the following files:  
foobar.rb

…so I assume it knows about the profile.rb model. Why is it saying  
Profile is an uninitialized constant, and why does this braindead  
simple code work fine in an older version of Rails but not the latest?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 15, 2007, 9:26am UTC](https://www.ruby-forum.com/t/very-simple-code-throwing-uninitialized-constant-error/117243/2 "2007-10-15T09:26:02Z")

</div>

On 15 Oct 2007, at 07:10, removed\_email\_address@domain.invalid wrote:

> …so I assume it knows about the profile.rb model. Why is it saying  
> Profile is an uninitialized constant, and why does this braindead  
> simple code work fine in an older version of Rails but not the latest?

I’ve seen ruby 1.8.6 get fussy about line endings in a way that  
previous versions weren’t. Check all your files use the same. I’d  
also check that the Globalize plugin is also being loaded properly  
Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 15, 2007, 9:54am UTC](https://www.ruby-forum.com/t/very-simple-code-throwing-uninitialized-constant-error/117243/3 "2007-10-15T09:54:06Z")

</div>

On 15 Oct 2007, at 08:43, removed\_email\_address@domain.invalid wrote:

> The globalize plugin appears to be working–I can switch between  
> languages on other pages. But I’m probably using an older version so  
> I’ll try updating it. But even if I comment out the “translates :text”  
> line in the Profile model, I still get the same error.
> 
> As for line endings, I don’t see any stray tabs, spaces or  
> nonprintable characters.  
> By line ending problems I mean some a file using dos line endings (on  
> a unix like machine) or vice versa.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 15, 2007, 9:52am UTC](https://www.ruby-forum.com/t/very-simple-code-throwing-uninitialized-constant-error/117243/4 "2007-10-15T09:52:20Z")

</div>

The globalize plugin appears to be working–I can switch between  
languages on other pages. But I’m probably using an older version so  
I’ll try updating it. But even if I comment out the “translates :text”  
line in the Profile model, I still get the same error.

As for line endings, I don’t see any stray tabs, spaces or  
nonprintable characters.

On Oct 15, 4:17 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 15, 2007, 9:54am UTC](https://www.ruby-forum.com/t/very-simple-code-throwing-uninitialized-constant-error/117243/5 "2007-10-15T09:54:41Z")

</div>

Since I originally created the application with an older version of  
Ruby and Rails, do I need to do something to update the application?  
Some kind of rake command?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 15, 2007, 10:22am UTC](https://www.ruby-forum.com/t/very-simple-code-throwing-uninitialized-constant-error/117243/6 "2007-10-15T10:22:47Z")

</div>

On 15 Oct 2007, at 08:45, removed\_email\_address@domain.invalid wrote:

> Since I originally created the application with an older version of  
> Ruby and Rails, do I need to do something to update the application?  
> Some kind of rake command?

There is rake rails:update which will update boot.rb and various  
things.

Fred
