Created
June 30, 2009 19:41
-
-
Save mpeychich/138364 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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