Sha256: 938e0822e38b8829cba1a9ca21e058bc71b5c47c82c84da55f18159cc4d6a7b3

Contents?: true

Size: 615 Bytes

Versions: 6

Compression:

Stored size: 615 Bytes

Contents

module Cmor::Blog
  class AssetDetail < ApplicationRecord
    belongs_to :post
    belongs_to :asset, class_name: 'ActiveStorage::Attachment', dependent: :destroy

    acts_as_list scope: :post_id

    # acts as published
    include ActsAsPublished::ActiveRecord
    acts_as_published

    scope :images,     -> { joins(asset: [:blob]).where("active_storage_blobs.content_type LIKE '%image/%'") }
    scope :non_images, -> { joins(asset: [:blob]).where("active_storage_blobs.content_type NOT LIKE '%image/%'") }

    def filename
      asset&.blob&.filename
    end

    def human
      filename
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cmor_blog-0.0.60.pre app/models/cmor/blog/asset_detail.rb
cmor_blog-0.0.59.pre app/models/cmor/blog/asset_detail.rb
cmor_blog-0.0.58.pre app/models/cmor/blog/asset_detail.rb
cmor_blog-0.0.57.pre app/models/cmor/blog/asset_detail.rb
cmor_blog-0.0.56.pre app/models/cmor/blog/asset_detail.rb
cmor_blog-0.0.55.pre app/models/cmor/blog/asset_detail.rb