ecole_eft_app/app/models/data_file.rb
2012-06-20 10:07:49 +02:00

34 lines
557 B
Ruby

# -*- encoding : utf-8 -*-
class DataFile < ActiveRecord::Base
belongs_to :file_folder
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