# const\_missing

**URL:** <https://discuss.rubyonrails.org/t/const-missing/35023>\
**Category:** rubyonrails-talk\
**Created:** [October 4, 2008, 7:37pm UTC](https://discuss.rubyonrails.org/t/const-missing/35023 "2008-10-04T19:37:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [October 4, 2008, 7:37pm UTC](https://discuss.rubyonrails.org/t/const-missing/35023/1 "2008-10-04T19: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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def index &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@article=Content.find(:all) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [October 4, 2008, 7:42pm UTC](https://discuss.rubyonrails.org/t/const-missing/35023/2 "2008-10-04T19:42:42Z")

</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

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

> 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/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:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [October 4, 2008, 7:56pm UTC](https://discuss.rubyonrails.org/t/const-missing/35023/3 "2008-10-04T19: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 &nbsp;&nbsp;set\_table\_name "content" &nbsp;&nbsp;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: &nbsp;&nbsp;adapter: mysql &nbsp;&nbsp;database: mydb &nbsp;&nbsp;username: myuser &nbsp;&nbsp;password: mypass &nbsp;&nbsp;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)

> > Content

NameError: uninitialized constant Content &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/dependencies.rb:279:in `load_missing_constant' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:468:in `const\_missing' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/dependencies.rb:480:in `const\_missing' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):1

> >

Any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [October 4, 2008, 8:18pm UTC](https://discuss.rubyonrails.org/t/const-missing/35023/4 "2008-10-04T20: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.
