| Class | Upload |
| In: |
app/models/upload.rb
|
| Parent: | ActiveRecord::Base |
| file | [RW] |
# File app/models/upload.rb, line 32
32: def file=(file)
33: @file = file
34: write_attribute 'filename', file.original_filename
35: write_attribute 'content_type', file.content_type.strip
36: end
after_save :process
# File app/models/upload.rb, line 24
24: def new_filename
25: return "#{self.id.to_s}.#{self.filename.split('.').last.downcase}"
26: end
# File app/models/upload.rb, line 28
28: def path
29: return "#{ENV['EPFWIKI_ROOT_DIR']}public/uploads/#{self.new_filename}"
30: end
# File app/models/upload.rb, line 38
38: def save_file
39: raise 'Cannot save without id' if self.id.nil?
40: uploads_path = "#{ENV['EPFWIKI_ROOT_DIR']}public/uploads/"
41: File.makedirs(uploads_path) if !File.exists?(uploads_path)
42: self.rel_path = write_attribute 'rel_path', "uploads/#{self.id.to_s}.#{self.filename.split('.').last.downcase}"
43: File.open(self.path, 'wb') do |file_date|
44: file_date.puts file.read
45: end
46: end