Sha256: b65239da7ecbe366a797dddc57daf58a82d94e76e099e20ddc73ccb78579dcea
Contents?: true
Size: 626 Bytes
Versions: 8
Compression:
Stored size: 626 Bytes
Contents
module Redde::WithPhoto extend ActiveSupport::Concern QUERY = 'imageable_id = :id AND imageable_type = :type OR token in (:tokens)' included do attr_accessor :photo_tokens has_many :photos, dependent: :destroy, as: :imageable after_create :assign_photos end def all_photos Photo.where(QUERY, id: self.id, type: self.class.name, tokens: tokens) end def assign_photos Photo.where(token: tokens).update_all(imageable_attributes) end def imageable_attributes { imageable_id: self.id, imageable_type: self.class.name, token: nil } end def tokens photo_tokens || [] end end
Version data entries
8 entries across 8 versions & 1 rubygems