Sha256: 65a652f6d3e5d8fa8e511f6bf48e0f55f4c3dfc6eee90a219f6a6b22da9be0ad

Contents?: true

Size: 722 Bytes

Versions: 26

Compression:

Stored size: 722 Bytes

Contents

module Spina
  class Attachment < ActiveRecord::Base
    
    has_one :page_part, as: :page_partable
    has_and_belongs_to_many :attachment_collections, join_table: 'spina_attachment_collections_attachments'

    attr_accessor :_destroy

    scope :sorted, -> { order('created_at DESC') }
    scope :file_attached, -> { where('file IS NOT NULL') }

    mount_uploader :file, FileUploader

    def name
      file.file.try(:filename)
    end

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

  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
spina-0.8.3 app/models/spina/attachment.rb
spina-0.8.2 app/models/spina/attachment.rb
spina-0.8.1 app/models/spina/attachment.rb
spina-0.8.0 app/models/spina/attachment.rb
spina-0.7.3 app/models/spina/attachment.rb
spina-0.7.2 app/models/spina/attachment.rb
spina-0.7.0 app/models/spina/attachment.rb
spina-0.6.29 app/models/spina/attachment.rb
spina-0.6.28 app/models/spina/attachment.rb
spina-0.6.27 app/models/spina/attachment.rb
spina-0.6.26 app/models/spina/attachment.rb
spina-0.6.25 app/models/spina/attachment.rb
spina-0.6.24 app/models/spina/attachment.rb
spina-0.6.23 app/models/spina/attachment.rb
spina-0.6.22 app/models/spina/attachment.rb
spina-0.6.21 app/models/spina/attachment.rb
spina-0.6.20 app/models/spina/attachment.rb
spina-0.6.19 app/models/spina/attachment.rb
spina-0.6.18 app/models/spina/attachment.rb
spina-0.6.17 app/models/spina/attachment.rb