# How to put the model class in module?

**URL:** <https://www.ruby-forum.com/t/how-to-put-the-model-class-in-module/86077>\
**Category:** Rails\
**Created:** [March 23, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/how-to-put-the-model-class-in-module/86077 "2006-03-23T17:00:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oliver\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ac91a4/32.png) [@Oliver\_P](https://www.ruby-forum.com/u/Oliver_P)\
**Post date:** [March 23, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/how-to-put-the-model-class-in-module/86077/1 "2006-03-23T17:00:39Z")

</div>

I meet a strange problem. I have a table name is application. So I have  
to use Application as the model class name. But it reports error. If I  
put the model class into my special module and require the file in  
controller, it works. But I find that all predefined methods in Active  
Record are no longer effective, such as validate and so on.

Can you please give me some idea on this problem? Thanks .

---

<div class="post-metadata">

**Author:** ![Oliver\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ac91a4/32.png) [@Oliver\_P](https://www.ruby-forum.com/u/Oliver_P)\
**Post date:** [March 23, 2006, 5:07pm UTC](https://www.ruby-forum.com/t/how-to-put-the-model-class-in-module/86077/2 "2006-03-23T17:07:21Z")

</div>

why not just do:

class AppModel \< ActiveRecord::Base  
set\_table\_name “application”  
end

or, the easiest way, rename your table so it doesn’t conflict with  
Rails.

Chris

---

<div class="post-metadata">

**Author:** ![Oliver\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ac91a4/32.png) [@Oliver\_P](https://www.ruby-forum.com/u/Oliver_P)\
**Post date:** [March 24, 2006, 6:15pm UTC](https://www.ruby-forum.com/t/how-to-put-the-model-class-in-module/86077/3 "2006-03-24T18:15:20Z")

</div>

Chris H. wrote:

> why not just do:
> 
> class AppModel \< ActiveRecord::Base  
> set\_table\_name “application”  
> end
> 
> or, the easiest way, rename your table so it doesn’t conflict with  
> Rails.
> 
> Chris

Thank your reply.

But the problem still exist. I have to put the AppModel class in my  
special module, otherwise the controller can’t find the new model. It  
will report that “uninitialized constant AppModel”. Can you please give  
some suggestion?

---

<div class="post-metadata">

**Author:** ![Oliver\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ac91a4/32.png) [@Oliver\_P](https://www.ruby-forum.com/u/Oliver_P)\
**Post date:** [March 24, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/how-to-put-the-model-class-in-module/86077/4 "2006-03-24T18:19:49Z")

</div>

Oliver P wrote:

> Chris H. wrote:
> 
> > why not just do:
> > 
> > class AppModel \< ActiveRecord::Base  
> > set\_table\_name “application”  
> > end
> > 
> > or, the easiest way, rename your table so it doesn’t conflict with  
> > Rails.
> > 
> > Chris
> 
> Thank your reply.
> 
> But the problem still exist. I have to put the AppModel class in my  
> special module, otherwise the controller can’t find the new model. It  
> will report that “uninitialized constant AppModel”. Can you please give  
> some suggestion?

hi,

I’m guessing that the controller is now not loading it automatically,  
you can tell it to do so using  
model :app\_model

–  
Agnieszka

---

<div class="post-metadata">

**Author:** ![Oliver\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ac91a4/32.png) [@Oliver\_P](https://www.ruby-forum.com/u/Oliver_P)\
**Post date:** [March 24, 2006, 8:01pm UTC](https://www.ruby-forum.com/t/how-to-put-the-model-class-in-module/86077/5 "2006-03-24T20:01:00Z")

</div>

I got it. Thank you very much!
