Skip to content

Instantly share code, notes, and snippets.

@mpeychich
Created June 30, 2009 19:41
Show Gist options
  • Save mpeychich/138364 to your computer and use it in GitHub Desktop.
Save mpeychich/138364 to your computer and use it in GitHub Desktop.
module HasAUMedia
def self.included(base)
base.class_eval do
has_many :attachments, :class_name => 'UserAttachment', :as => :attachable
has_many :videos, :class_name => 'UserAttachment::Video', :as => :attachable
has_many :images, :class_name => 'UserAttachment::Image', :as => :attachable
end
end
end
class Offergroup < ActiveRecord::Base
include HasAUMedia
end
# migration adds a type column and a user_id, updates data based on content_type and former user_id object
# add index on user_id and type
class Media < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true
validates_presence_of :user_id
end
class Media::Video < Media
# some validation against video related content type
end
class Media::Image < Media
# some validation against video related content type
end
class User < ActiveRecord::Base
include HasAUMedia
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment