ericindc
2009-Feb-27 21:17 UTC
Is a global set of named_scope scopes a bad idea? If not, is it possible?
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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Starr Horne
2009-Feb-27 21:34 UTC
Re: Is a global set of named_scope scopes a bad idea? If not, is it possible?
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ericindc
2009-Feb-27 22:23 UTC
Re: Is a global set of named_scope scopes a bad idea? If not, is it possible?
No, I didn''t try that but that worked perfectly. Thanks for the tip. On Feb 27, 4:34 pm, Starr Horne <st...-wG8FsLYNbnsysxA8WJXlww@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---