# Attachment\_fu - one or multiple attachment tables?

**URL:** <https://www.ruby-forum.com/t/attachment-fu-one-or-multiple-attachment-tables/86361>\
**Category:** Rails\
**Created:** [February 21, 2007, 6:53pm UTC](https://www.ruby-forum.com/t/attachment-fu-one-or-multiple-attachment-tables/86361 "2007-02-21T18:53:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f475e1/32.png) [@ralph](https://www.ruby-forum.com/u/ralph)\
**Post date:** [February 21, 2007, 6:53pm UTC](https://www.ruby-forum.com/t/attachment-fu-one-or-multiple-attachment-tables/86361/1 "2007-02-21T18:53:31Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![ralph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f475e1/32.png) [@ralph](https://www.ruby-forum.com/u/ralph)\
**Post date:** [February 22, 2007, 12:43am UTC](https://www.ruby-forum.com/t/attachment-fu-one-or-multiple-attachment-tables/86361/2 "2007-02-22T00:43:59Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![ralph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f475e1/32.png) [@ralph](https://www.ruby-forum.com/u/ralph)\
**Post date:** [February 22, 2007, 9:10am UTC](https://www.ruby-forum.com/t/attachment-fu-one-or-multiple-attachment-tables/86361/3 "2007-02-22T09:10:54Z")

</div>

Thank you very much Peter, this is what I wanted to hear!
