What is the best way to handle multiple attachments in rails projects?

sadfuzzy Posted by sadfuzzy on November 13, 2012

What is the best way to handle multiple attachments in rails projects?

I have a post. I want to attach different kinds of content (audio/document/photo/video) and display them. I want to be able to use same attachments in different posts. How I should implement this (if i use gem carrierwave, for example)?

This works, but i'd like to separate each kind of content to different models and tables (there will be lots of content):

class Attachment < ActiveRecord::Base
  attr_accessible :post_id, :image, :remote_image_url, :document, :remote_document_url, :video, :remote_video_url
  belongs_to :post
  belongs_to :user

  mount_uploader :image, ImageUploader
  mount_uploader :document, DocumentUploader
  mount_uploader :video, VideoUploader
end

Answers