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