Sha256: a6c414ef38c49abbc3e452c0c3fd7ad518fb70e7e3a66228f6f865b68fa9b6c0

Contents?: true

Size: 497 Bytes

Versions: 1

Compression:

Stored size: 497 Bytes

Contents

module Spina
  class Attachment < ApplicationRecord
    has_one_attached :file

    attr_accessor :_destroy

    scope :sorted, -> { order('created_at DESC') }

    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

1 entries across 1 versions & 1 rubygems

Version Path
spina-2.1.0 app/models/spina/attachment.rb