Älphä Blüë wrote: > Hi all, > > I just have a question about shared model methods. I have a method that > will be used for quite a few models in my application (once I've cleaned > it up a bit). Where can I place shared model methods? I know that > controllers can use helpers or even the application_controller. But, > what do models use for a shared mechanism? Is it config/initialize? > > Can someone explain a quick process for it? >
Depending on how big the sharing ends up (my app is about 85% shared functionality among models), you can always create an abstract model class that defines those capabilities, then inherit concrete models from that. class GenericModel < ActiveRecord::Base self.abstract_class = true # generic implementations shared by all models # my app has some 30 'generic' model methods, relationship # management, cache management, pdf generation, etc end class Project < GenericModel # project-specific methods # project has only 5, 2 of which override GenericModel # definitions end You can do the same thing with controllers as well... GenericController has all the common stuff (index, show, edit, etc, etc) ProjectsController has just the project specific stuff. Whatever works for you. -- 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

