Sha256: 813c7c1d3d663e540e4327362c0caa83db5bc7b05bfae7b072a011ad97569379

Contents?: true

Size: 580 Bytes

Versions: 1

Compression:

Stored size: 580 Bytes

Contents

module Thredded
  class Attachment < ActiveRecord::Base
    belongs_to :post, touch: true
    validates_presence_of :attachment
    mount_uploader :attachment, Thredded::AttachmentUploader
    before_save :update_attachment_attributes

    def cache_dir
      "#{Rails.root}/tmp/uploads"
    end

    def filename
      File.basename(attachment.path)
    end

    def update_attachment_attributes
      if attachment.present? && attachment_changed?
        self.content_type = attachment.file.content_type
        self.file_size = attachment.file.size
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thredded-0.0.12 app/models/thredded/attachment.rb