Topic: Share same code with multiple models
I have multiple models that need to share the same piece of code, and I cannot find a way to DRY the whole thing. Of course I can cut and paste the same lines of code in every single model but there has to be a way to put this code in a single place and use it.
A brief description:
I have a Document model using attachment_fu for storing attachments.
In each model where i need to link an attached document (ie Offer, Product, etc) i need to put the code used to save the attachment and link it to the main module (Fat Model/Skinny Controller).
The shared code is the has_many declaration, the attr_writer definition, two callbacks (after_create and after_update) and two private methods used to save the Document after linking it to the model.
Any hint on where to put all these things?