Sha256: 978fa268449dfddea9fb93ac13c217a9bcf2503340afecd943fa0897357eb700

Contents?: true

Size: 567 Bytes

Versions: 8

Compression:

Stored size: 567 Bytes

Contents

module Thredded
  class Attachment < ActiveRecord::Base
    belongs_to :post
    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

8 entries across 8 versions & 1 rubygems

Version Path
thredded-0.0.10 app/models/thredded/attachment.rb
thredded-0.0.9 app/models/thredded/attachment.rb
thredded-0.0.8 app/models/thredded/attachment.rb
thredded-0.0.7 app/models/thredded/attachment.rb
thredded-0.0.6 app/models/thredded/attachment.rb
thredded-0.0.5 app/models/thredded/attachment.rb
thredded-0.0.4 app/models/thredded/attachment.rb
thredded-0.0.3 app/models/thredded/attachment.rb