Hi, I''d like to add a generic function to all my models. Basically a function that will handle setting/unsetting flags in various models. Is there a way I could add this to ActiveRecord''s Base class and then use it all throughout my models? Where could I add this and how? Thanks, Sam -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 10/2/06, Sam Donaldson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, I''d like to add a generic function to all my models. Basically a > function that will handle setting/unsetting flags in various models. Is > there a way I could add this to ActiveRecord''s Base class and then use > it all throughout my models? Where could I add this and how? > > Thanks, > > SamIn the lib directory create a file and in it use module ActiveRecord class Base def my_method end end I think that should be automatically loaded and included (not sure if it''s completely automagic). Alternatively you can put that in you environment.rband it will get included. I''m sure there are many other ways of doing this though. This may not be the best one. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Oct 2, 2006, at 7:40 AM, Sam Donaldson wrote:> Hi, I''d like to add a generic function to all my models. Basically a > function that will handle setting/unsetting flags in various > models. Is > there a way I could add this to ActiveRecord''s Base class and then use > it all throughout my models? Where could I add this and how?Just subclass ActiveRecord::Base: class MyBaseExtension < ActiveRecord::Base self.abstract_class = true # ... end and then make all models inherit from MyBaseExtension. -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
There is (also) a toggle on ActiveRecord which is really useful. http://ar.rubyonrails.com/classes/ActiveRecord/Base.html#M000399 Vish On 10/2/06, Xavier Noria <fxn-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> > > On Oct 2, 2006, at 7:40 AM, Sam Donaldson wrote: > > > Hi, I''d like to add a generic function to all my models. Basically a > > function that will handle setting/unsetting flags in various > > models. Is > > there a way I could add this to ActiveRecord''s Base class and then use > > it all throughout my models? Where could I add this and how? > > Just subclass ActiveRecord::Base: > > class MyBaseExtension < ActiveRecord::Base > self.abstract_class = true > # ... > end > > and then make all models inherit from MyBaseExtension. > > -- fxn > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---