Storing attachments in separate table

27 views
Skip to first unread message

Joe Van Dyk

unread,
Sep 24, 2008, 11:36:23 PM9/24/08
to Paperclip Plugin
Hi,

I have a Group that has three images (logo, banner, and background
image). Right now, I'd have to add 12 tables to the groups table,
right? That sort of sucks.

attachment_fu is nice in that attachments are kept in a separate
table. But the code in attachment_fu makes me cry, so that's why I'm
interested in paperclip.

Any thoughts?

linojon

unread,
Sep 24, 2008, 11:47:13 PM9/24/08
to papercli...@googlegroups.com
there's nothing to say you cant have a paperclip model Image with
just one attachment, and then associate it with your Group.
I do this. But If you name the column 'image', then you get ugly
stuff like @image.image_file_name,
or worse a File model with a 'file' column name might end up with
@file.file_file_name :) so I alias the common accessors for readability.

linoj

Jonathan Yurek

unread,
Sep 25, 2008, 7:57:49 AM9/25/08
to papercli...@googlegroups.com
Hi,

Not all of the columns are required, but in any case, putting the
attachment on a separate model and associating via has_many (or 3
belongs_to or has_one, in your case) is a perfectly valid way of using
paperclip.

Joe Van Dyk

unread,
Sep 25, 2008, 6:14:37 PM9/25/08
to Paperclip Plugin
Would it be a good idea to have something like:

class Upload < AR

class Logo < Upload
has_attached_file :image

class BackgroundImage < Upload
has_attached_file :image

class Banner < Upload
has_attached_file :image

Reason is because the Logo, BackgroundImage, and Banner all have to be
resized differently.

On Sep 25, 4:57 am, Jonathan Yurek <jyu...@thoughtbot.com> wrote:
> Hi,
>
> Not all of the columns are required, but in any case, putting the  
> attachment on a separate model and associating via has_many (or 3  
> belongs_to or has_one, in your case) is a perfectly valid way of using  
> paperclip.
>

Jonathan Yurek

unread,
Sep 26, 2008, 11:09:53 AM9/26/08
to papercli...@googlegroups.com
That seems to be an decent use of subclassing. There's no specific
reason it wouldn't work.

--
Jonathan Yurek, Founder and CTO
thoughtbot, inc.
organic brains. digital solutions.

617.482.1300 x114
http://www.thoughtbot.com/

Reply all
Reply to author
Forward
0 new messages