Forum: Ruby on Rails attachment_fu - one or multiple attachment tables?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
rv d. (Guest)
on 2007-02-21 19:53
Hello,

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?
Peter De Berdt (Guest)
on 2007-02-22 01:43
(Received via mailing list)
On 21 Feb 2007, at 18:53, rv dh wrote:

> 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, Â…)



Best regards

Peter De Berdt
rv d. (Guest)
on 2007-02-22 10:10
Thank you very much Peter, this is what I wanted to hear!
This topic is locked and can not be replied to.