Sha256: 5fbb70e762d79a747f7ccd1d575d2fcbb17083d64069a4b4daf16342c5bd63c5

Contents?: true

Size: 811 Bytes

Versions: 17

Compression:

Stored size: 811 Bytes

Contents

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

  belongs_to :attachable, polymorphic: true
  belongs_to :sender, class_name: User

  belongs_to :attachment_type, required: false

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

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

  default_scope -> {
    all
      .order(created_at: :desc, id: :desc)
      .preload(:attachment_type)
  }

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

  private

  before_save :assign_default_name

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
dorsale-3.9.6 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.9.5 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.9.4 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.9.3 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.9.2 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.9.1 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.9.0 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.8.1 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.8.0 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.7.8 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.7.7 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.7.6 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.7.5 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.7.4 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.7.2 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.7.1 app/models/dorsale/alexandrie/attachment.rb
dorsale-3.7.0 app/models/dorsale/alexandrie/attachment.rb