Sha256: 60682732f4bc4617a078dc13ffdf0bb6683af9d6c994677b07c1bd8395300aa5

Contents?: true

Size: 727 Bytes

Versions: 3

Compression:

Stored size: 727 Bytes

Contents

class Dorsale::Alexandrie::Attachment < ActiveRecord::Base
  self.table_name = "dorsale_alexandrie_attachments"

  belongs_to :attachable, polymorphic: true
  belongs_to :sender,     polymorphic: true

  belongs_to :attachment_type, required: false

  validates :attachable, presence: true
  validates :file,       presence: true

  mount_uploader :file, ::Dorsale::Alexandrie::FileUploader

  before_save :set_default_name

  default_scope -> {
    order(id: :desc)
  }

  def set_default_name
    self.name = file_identifier if name.blank?
  end

  def download_filename
    if File.extname(file_identifier) == File.extname(name)
      name
    else
      name.parameterize + File.extname(file_identifier)
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dorsale-3.1.6 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.1.5 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.1.4 app/models/dorsale/alexandrie/attachment.rb