# Is a global set of named\_scope scopes a bad idea? If not, is it possible?

**URL:** <https://www.ruby-forum.com/t/is-a-global-set-of-named-scope-scopes-a-bad-idea-if-not-is-it-possible/161619>\
**Category:** Rails\
**Created:** [February 27, 2009, 10:17pm UTC](https://www.ruby-forum.com/t/is-a-global-set-of-named-scope-scopes-a-bad-idea-if-not-is-it-possible/161619 "2009-02-27T22:17:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [February 27, 2009, 10:17pm UTC](https://www.ruby-forum.com/t/is-a-global-set-of-named-scope-scopes-a-bad-idea-if-not-is-it-possible/161619/1 "2009-02-27T22:17:47Z")

</div>

I’ve noticed that several of my models contain the same set of  
named\_scopes (ones for active, various access levels, etc.). I was  
thinking to avoid the duplication I’d try to pull that coat into a  
common file either included or extended from within my models.

I created a module, but that didn’t seem to work w/ errors trying to  
use named\_scope. I create a “base” model and made the other models  
child classes to it, but Rails looked for a bases table, which makes  
sense, but unfortunately the table doesn’t exist.

Is this possible or am I stuck duplicating the named\_scopes across all  
of my models?

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [February 27, 2009, 10:37pm UTC](https://www.ruby-forum.com/t/is-a-global-set-of-named-scope-scopes-a-bad-idea-if-not-is-it-possible/161619/2 "2009-02-27T22:37:09Z")

</div>

When you tried using a module, did you try it like this? ie. putting the  
calls to named\_scope inside self.included ?

module MyScopes  
def self.included(base)  
base.send :named\_scope, … params …

Another option might be to make a plugin with your named scopes in them.

SH

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [February 27, 2009, 11:24pm UTC](https://www.ruby-forum.com/t/is-a-global-set-of-named-scope-scopes-a-bad-idea-if-not-is-it-possible/161619/3 "2009-02-27T23:24:02Z")

</div>

No, I didn’t try that but that worked perfectly. Thanks for the tip.
