I am currently writing a rails application which includes multiple
models that require attachments. Each model object does have zero or one
attachment. The attributes to be saved on each attachment do not differ.
I want to use attachment_fu, the successor of the acts_as_attachment
plugin.
My initial guess was to create one attachment table and use polymorphic
associations to associate model objects with their corresponding
attachments.
To my surprise, this tutorial for acts_as_attachment
(http://weblog.techno-weenie.net/articles/acts_as_attachment) states:
“Acts as Attachment is designed to be specified on multiple models in
your application, rather than having a global Attachment model that
other models depend on.”
Is there a reason for this behaviour? Is my initial idea possible as
well?
associations to associate model objects with their corresponding
attachments.
To my surprise, this tutorial for acts_as_attachment
(http://weblog.techno-weenie.net/articles/acts_as_attachment) states:
“Acts as Attachment is designed to be specified on multiple models in
your application, rather than having a global Attachment model that
other models depend on.”
Is there a reason for this behaviour? Is my initial idea possible as
well?
You can perfectly create a single Attachment class and
polymorphically link several other models of your application to it.
However, acts_as_attachment and attachment_fu don’t force you into
any constraint and it can be quite handy for logical data separation
to use several tables for different purposes (e.g. avatars table,
image_uploads table, Â…)