37 lines
703 B
Ruby
37 lines
703 B
Ruby
# -*- encoding : utf-8 -*-
|
|
class NoteFile < ActiveRecord::Base
|
|
|
|
attr_accessor :original_filename
|
|
#attr_accessible :description, :file, :name, :slug, :note, :note_id, :file_cache, :original_filename
|
|
belongs_to :note
|
|
mount_uploader :file, FileUploader
|
|
|
|
|
|
before_save do
|
|
if !self.name?
|
|
self.name = File.basename(self.file.filename, File.extname(self.file.filename)).to_s if self.file?
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def file_type
|
|
|
|
|
|
mime = `file --mime -br "#{self.file.path}"`.strip.split(';')[0]
|
|
mime
|
|
|
|
end
|
|
|
|
def abstract_file_name
|
|
self.name+File.extname(self.attributes['file'])
|
|
end
|
|
|
|
def abstract_file_name_slug
|
|
self.name.to_slug+File.extname(self.attributes['file'])
|
|
end
|
|
|
|
end
|