You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

37 lines
981 B

module HasAttachments
extend ActiveSupport::Concern
included do
has_many :attachments, -> { order :position }, dependent: :destroy, as: :attachable_for, class_name: "Attachment"
has_many :assets, through: :attachments
has_many :assets,
through: :attachments,
source: :asset
#has_many :images,
# -> { with_attached_file.where('assets.content_type LIKE ?', "image/%") },
# through: :attachments,
# source: :asset
#
#has_many :images_favorites_first,
# -> { with_attached_file.where('assets.content_type LIKE ?', "image/%").reorder('attachments.is_favorite DESC', 'attachments.position ASC') },
# through: :attachments,
# source: :asset
accepts_nested_attributes_for :attachments, allow_destroy: true
end
def icon
self.assets.map{ |asset| return asset if asset.file and asset.file.content_type.starts_with?('image/') }
nil
end
end