# Cannot use "Application" as a model?

**URL:** <https://www.ruby-forum.com/t/cannot-use-application-as-a-model/154106>\
**Category:** Rails\
**Created:** [November 25, 2008, 1:32pm UTC](https://www.ruby-forum.com/t/cannot-use-application-as-a-model/154106 "2008-11-25T13:32:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/47e85d/32.png) [@tick](https://www.ruby-forum.com/u/tick)\
**Post date:** [November 25, 2008, 1:32pm UTC](https://www.ruby-forum.com/t/cannot-use-application-as-a-model/154106/1 "2008-11-25T13:32:20Z")

</div>

I tried creating an application that has an “Application” model. This  
seems to collide with the “ApplicationController” defined in  
application.rb.

For example…  
rails appgoboom  
cd appgoboom  
script/generate scaffold Application name:string  
script/console  
Loading development environment (Rails 2.2.2)

> > Application.find(:all)  
> > LoadError: Expected /home/rkrueger/source/rails/appgoboom/app/  
> > controllers/application.rb to define Application  
> > from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/  
> > active\_support/dependencies.rb:428:in `load_missing_constant' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/ active_support/dependencies.rb:77:in`const\_missing’  
> > from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/  
> > active\_support/dependencies.rb:89:in `const\_missing’  
> > from (irb):1

I get the same error when running the application using script/server:  
“Expected /home/rkrueger/source/rails/appgoboom/app/controllers/  
application.rb to define Application”

I’ve been trying to go through the thesaurus in my head to find other  
names to use than “Application”, but honestly Application is what I  
want. Everything else sounds lame…

---

<div class="post-metadata">

**Author:** ![tick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/47e85d/32.png) [@tick](https://www.ruby-forum.com/u/tick)\
**Post date:** [November 25, 2008, 3:38pm UTC](https://www.ruby-forum.com/t/cannot-use-application-as-a-model/154106/2 "2008-11-25T15:38:05Z")

</div>

> That’s about right. Because there is an application.rb in an  
> appropriate place in the search path Rails may find that file and try  
> to load it first. While you might be able to fiddle with those so that  
> rails found your model class first that would then probably screw  
> things up when Rails is actually looking for ApplicationController.  
> You might be able to get round this by just explicitly loading your  
> model rather than relying on the magical loading

Lame! 😛

Thanks for the tip Frederick, would you be able to clue me into where  
I can read about doing that?  
I’m too new at this to know how to do anything other than “magical  
loading” heh.

> Wait for Rails 2.3 where ApplicationController will live in  
> application\_controller.rb 🙂

Yeah thought about that, I wasn’t sure if Edge was too shaky right now  
to try and jump on that though.

---

<div class="post-metadata">

**Author:** ![tick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/47e85d/32.png) [@tick](https://www.ruby-forum.com/u/tick)\
**Post date:** [November 25, 2008, 1:35pm UTC](https://www.ruby-forum.com/t/cannot-use-application-as-a-model/154106/3 "2008-11-25T13:35:53Z")

</div>

On Nov 25, 12:14 pm, Ray K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I tried creating an application that has an “Application” model. This  
> seems to collide with the “ApplicationController” defined in  
> application.rb.

That’s about right. Because there is an application.rb in an  
appropriate place in the search path Rails may find that file and try  
to load it first. While you might be able to fiddle with those so that  
rails found your model class first that would then probably screw  
things up when Rails is actually looking for ApplicationController.  
You might be able to get round this by just explicitly loading your  
model rather than relying on the magical loading

Wait for Rails 2.3 where ApplicationController will live in  
application\_controller.rb 🙂

Fred

---

<div class="post-metadata">

**Author:** ![tick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/47e85d/32.png) [@tick](https://www.ruby-forum.com/u/tick)\
**Post date:** [November 25, 2008, 3:41pm UTC](https://www.ruby-forum.com/t/cannot-use-application-as-a-model/154106/4 "2008-11-25T15:41:01Z")

</div>

On 25 Nov 2008, at 14:37, Ray K. wrote:

> Lame! 😛
> 
> Thanks for the tip Frederick, would you be able to clue me into where  
> I can read about doing that?  
> I’m too new at this to know how to do anything other than “magical  
> loading” heh.

Put your model class in something called not application.rb.  
Then use require\_dependency to require that file. Where exactly you do  
that is up for some debate but you could start with the bottom of  
application.rb (as in where ApplicationController sits)

Fred
