Re: Adding a method to ActiveRecord.

Daniel N
Mon, 02 Oct 2006 05:57:38 -0000

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,
>
> Sam


In 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.