# Shared Model Methods

**URL:** <https://discuss.rubyonrails.org/t/shared-model-methods/43883>\
**Category:** rubyonrails-talk\
**Created:** [July 1, 2009, 8:28pm UTC](https://discuss.rubyonrails.org/t/shared-model-methods/43883 "2009-07-01T20:28:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff1](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/jeff1/32/1170_2.png) [@Jeff1](https://discuss.rubyonrails.org/u/Jeff1)\
**Post date:** [July 1, 2009, 8:28pm UTC](https://discuss.rubyonrails.org/t/shared-model-methods/43883/1 "2009-07-01T20:28:38Z")

</div>

> Hi all,
> 
> I just have a question about shared model methods. I have a method that will be used for quite a few models in my application (once I've cleaned it up a bit). Where can I place shared model methods? I know that controllers can use helpers or even the application\_controller. But, what do models use for a shared mechanism? Is it config/initialize?

Yes, just use Ruby modules.

module SharedMethods

&nbsp;&nbsp;def list &nbsp;&nbsp;&nbsp;&nbsp;# ... &nbsp;&nbsp;end end

And in your model,

class MyModel \< ActiveRecord::Base

extend SharedMethods

end

Does this help?

Jeff

Rails for Everyone: Oct 24, 2009 in Chicago: [http://www.purpleworkshops.com/workshops/rails-for-everyone](http://www.purpleworkshops.com/workshops/rails-for-everyone)

---

<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:** [July 1, 2009, 8:45pm UTC](https://discuss.rubyonrails.org/t/shared-model-methods/43883/2 "2009-07-01T20:45:15Z")

</div>

Thanks a lot Jeff - yeah that's what I'm looking for. Does the ruby module have to belong in a certain place in my project to be usable by other models?

---

<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:** [July 1, 2009, 9:47pm UTC](https://discuss.rubyonrails.org/t/shared-model-methods/43883/3 "2009-07-01T21:47:56Z")

</div>

I figured it out. I actually made it simpler for me since I will be using a lot of methods (duplicate) for 37 different models.

I just created a plugin..

script/generate plugin template\_searches

init.rb added..

ActiveRecord::Base.send :include, TemplateSearches

template\_searches.rb added..

module TemplateSearches &nbsp;&nbsp;def self.included(base) &nbsp;&nbsp;&nbsp;&nbsp;base.extend(ClassMethods) &nbsp;&nbsp;end

&nbsp;&nbsp;module ClassMethods

&nbsp;&nbsp;My Methods...

&nbsp;&nbsp;end end

Removed the duplicate code and restarted and all is working well.
