Sha256: c1993d02697bd3c71031121877460e49722a86591ef506808ec1f8af58d04a7c

Contents?: true

Size: 490 Bytes

Versions: 5

Compression:

Stored size: 490 Bytes

Contents

module Spina
  class Attachment < ApplicationRecord
    has_one_attached :file

    attr_accessor :_destroy

    scope :sorted, -> { order('file ASC') }

    def name
      file.filename.to_s
    end

    def content
      file if file.attached?
    end

    alias_method :old_update, :update
    def update(attributes)
      if attributes["_destroy"] == "1" && attributes["file"].blank?
        self.page_part.destroy
      else
        old_update(attributes)
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spina-2.0.2 app/models/spina/attachment.rb
spina-2.0.1 app/models/spina/attachment.rb
spina-2.0.0 app/models/spina/attachment.rb
spina-2.0.0.beta app/models/spina/attachment.rb
spina-2.0.0.alpha app/models/spina/attachment.rb