I just posted a similar question regarding best practices when you have 
methods you want to share across multiple AR models.

I ended up writing a module and sticking it in the lib directory. In 
order to make these methods available to your models, simply include it 
with:

class Post < ActiveRecord::Base
  include MyModule
end

That seems to be a very neat and clean way to juggle these methods and 
DRY up your model code somewhat.

-- Josh
http://iammrjoshua.com


Brandon Keepers wrote:
> On Wed, Jan 14, 2009 at 8:26 PM, Pardee, Roy <parde...@ghc.org> wrote:
>>          kid.attributes = atts
>> I'd like to write these methods once generically & call the generic versions 
>> from the various models where I need to do this.  But it seems that helper 
>> methods aren't visible from within a model (right?).  Where can I put these 
>> generic methods so that they're visible from my models?  I'm using rails 
>> 2.0.2.
> You may want to check out the attribute_fu plugin:
> http://github.com/giraffesoft/attribute_fu/commits/master
> 
> This wraps up this pattern cleaner than I could in my vain attempts.
> It also provides some view helpers for displaying the models.
> 
> -- Brandon
> --------------------------------------------------------------------------------
> Training by Collective Idea: Ruby on Rails training in a vacation 
> setting
> http://training.collectiveidea.com � San Antonio, TX � Jan 20-23

-- 
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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to