# Const\_missing

**URL:** <https://www.ruby-forum.com/t/const-missing/150157>\
**Category:** Rails\
**Created:** [October 4, 2008, 9:37pm UTC](https://www.ruby-forum.com/t/const-missing/150157 "2008-10-04T21:37:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bizzz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bizzz](https://www.ruby-forum.com/u/bizzz)\
**Post date:** [October 4, 2008, 9:37pm UTC](https://www.ruby-forum.com/t/const-missing/150157/1 "2008-10-04T21:37:23Z")

</div>

I’ve run into what I suspect is a total newbie error. Any help  
appreciated!

I have a mysql db table called “content”.

I created a model rb class called app/models/content.rb

class Content \< ActiveRecord::Base  
end

I setup a controller file like this:

class NewsController \< ApplicationController  
def index  
@article=Content.find(:all)  
end  
end

And I have a simple index view file, views/index.rhtml

I hit the url:  
[http://localhost:3000/news/index/](http://localhost:3000/news/index/)

and I get this meaningless error:

/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/dependencies.rb:493:in  
`const_missing' app/controllers/news_controller.rb:3:in `index’

My config/database.yml is set to point to my local mysql db.

Ruby version 1.8.6 (i686-darwin8.11.1)  
RubyGems version 1.3.0  
Rails version 2.1.1  
Active Record version 2.1.1  
Action Pack version 2.1.1  
Active Resource version 2.1.1  
Action Mailer version 2.1.1  
Active Support version 2.1.1  
Application root /Users/andrew/dev/ruby/myapps/jazzhouston  
Environment development  
Database adapter mysql  
Database schema version 0

Any ideas?

---

<div class="post-metadata">

**Author:** ![bizzz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bizzz](https://www.ruby-forum.com/u/bizzz)\
**Post date:** [October 4, 2008, 9:43pm UTC](https://www.ruby-forum.com/t/const-missing/150157/2 "2008-10-04T21:43:44Z")

</div>

On Oct 4, 8:37 pm, Andrew L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’ve run into what I suspect is a total newbie error. Any help  
> appreciated!
> 
> I have a mysql db table called “content”.
> 
> I created a model rb class called app/models/content.rb

for a class called Content, the table name should be contents

> And I have a simple index view file, views/index.rhtml
> 
> I hit the url:[http://localhost:3000/news/index/](http://localhost:3000/news/index/)
> 
> and I get this meaningless error:
> 
> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/de pendencies.rb:493:in  
> `const_missing' app/controllers/news_controller.rb:3:in `index’

That means that when it got to line 3 in your controller it hit a  
constant it couldn’t fine (Content by the looks of it). Not sure why,  
given the information you’ve given. The full error trace might have  
more info, it could also indicate that something bad happened while  
loading content.db. If that is the case then running script/console  
and evaluating just  
Content  
should give a more helpful error.

Fred

---

<div class="post-metadata">

**Author:** ![bizzz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bizzz](https://www.ruby-forum.com/u/bizzz)\
**Post date:** [October 4, 2008, 9:56pm UTC](https://www.ruby-forum.com/t/const-missing/150157/3 "2008-10-04T21:56:04Z")

</div>

> for a class called Content, the table name should be contents

Thanks – I just found the details on how to handle that:

class Content \< ActiveRecord::Base  
set\_table\_name “content”  
set\_primary\_key “content\_id”  
end

(Note: Do I need to bounce the server (I did) anytime a model change  
happens?)

My database.yml looks like this:

development:  
adapter: mysql  
database: mydb  
username: myuser  
password: mypass  
host: localhost

And the same for test and production

Running the console gives this:

MacBook-Pro:~/dev/ruby/myapps/jazzhouston$ script/console  
Loading development environment (Rails 2.1.1)  
Consol\>\> Content  
NameError: uninitialized constant Content  
from  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/dependencies.rb:279:in  
`load_missing_constant' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:468:in`const\_missing’  
from  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/dependencies.rb:480:in  
`const\_missing’  
from (irb):1

> >

Any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![bizzz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bizzz](https://www.ruby-forum.com/u/bizzz)\
**Post date:** [October 4, 2008, 10:18pm UTC](https://www.ruby-forum.com/t/const-missing/150157/4 "2008-10-04T22:18:26Z")

</div>

Well every mistake teaches you something, and I definitely learned a bit  
about RoR today!

The problem? A typo! I had my model file named content.db instead of  
content.rb

I found this by debugging inside of lib/active\_support/dependencies.rb

Duh. Thanks again.
