# Modules in rails? ( controllers or models?)

**URL:** <https://www.ruby-forum.com/t/modules-in-rails-controllers-or-models/121931>\
**Category:** Ruby\
**Created:** [December 3, 2007, 12:41am UTC](https://www.ruby-forum.com/t/modules-in-rails-controllers-or-models/121931 "2007-12-03T00:41:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![malugu\_satyajit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f9ae1b/32.png) [@malugu\_satyajit](https://www.ruby-forum.com/u/malugu_satyajit)\
**Post date:** [December 3, 2007, 12:41am UTC](https://www.ruby-forum.com/t/modules-in-rails-controllers-or-models/121931/1 "2007-12-03T00:41:37Z")

</div>

Hello,

I have an rails application that has almost similar function for three  
classes. So I am thinking to create a parent class and then the sub  
classes  
inherit from it. But rails already inherits from ActiveRecord(models) or  
ApplicationController(controller).

So how can I inherit from others classes. My my ruby knowledge it is  
modules  
and then you mixin the module in your class.

Now my question, where you write the module in rails is it in controller  
or  
model? Can some one provide me links or guidance.

---

<div class="post-metadata">

**Author:** ![malugu\_satyajit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f9ae1b/32.png) [@malugu\_satyajit](https://www.ruby-forum.com/u/malugu_satyajit)\
**Post date:** [December 3, 2007, 12:49am UTC](https://www.ruby-forum.com/t/modules-in-rails-controllers-or-models/121931/2 "2007-12-03T00:49:48Z")

</div>

On Dec 2, 2007, at 6:40 PM, malugu satyajit wrote:

> is modules  
> and then you mixin the module in your class.
> 
> Now my question, where you write the module in rails is it in  
> controller or  
> model? Can some one provide me links or guidance.

You can create a parent class that inherits from ActiveRecord or  
ApplicationController.  
Then, your subclasses can inherit from the parent class.

This may or may not work, and this is a question for the rails list

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_|

- Ari  
I just bought another case of RockStar. Expect architectural changes.

---

<div class="post-metadata">

**Author:** ![malugu\_satyajit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f9ae1b/32.png) [@malugu\_satyajit](https://www.ruby-forum.com/u/malugu_satyajit)\
**Post date:** [December 3, 2007, 12:59am UTC](https://www.ruby-forum.com/t/modules-in-rails-controllers-or-models/121931/3 "2007-12-03T00:59:09Z")

</div>

thanks… can you say the rails list address? I found it on web… but  
just  
be sure

---

<div class="post-metadata">

**Author:** ![malugu\_satyajit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f9ae1b/32.png) [@malugu\_satyajit](https://www.ruby-forum.com/u/malugu_satyajit)\
**Post date:** [December 3, 2007, 1:07am UTC](https://www.ruby-forum.com/t/modules-in-rails-controllers-or-models/121931/4 "2007-12-03T01:07:21Z")

</div>

On Dec 2, 2007 5:40 PM, malugu satyajit [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Now my question, where you write the module in rails is it in controller or  
> model? Can some one provide me links or guidance.

Well, from a kindergartener’s perspective (namely, mine), I would  
think that if your classes represent tuples of data in a database,  
they would be models, and you would add functionality by having the  
model classes (those that inherit from ActiveRecord::Base) require the  
necessary mixin themselves, or make use of #extend. I think, however,  
it is highly dependent on your situation.

I’m sure you can find some best practices advice from the rails list.  
The one I have bookmarked is:  
[http://groups.google.com/group/rubyonrails-talk](http://groups.google.com/group/rubyonrails-talk).

Todd
