Class | Upload
In: | app/models/upload.rb
Parent: | ActiveRecord::Base

Copyright (c) 2006 Logica

### Methods

file= new_filename path save_file url

### Attributes

file | [RW] |

### Public Instance methods

file=(file)

[Source]

        # 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

new_filename()

after_save :process

[Source]

        # File app/models/upload.rb, line 24
    24:   def new_filename
    25:     return  "#{self.id.to_s}.#{self.filename.split('.').last.downcase}"
    26:   end

path()

[Source]

        # File app/models/upload.rb, line 28
    28:   def path
    29:     return "#{ENV['EPFWIKI_ROOT_DIR']}public/uploads/#{self.new_filename}"
    30:   end

save_file()

[Source]

        # 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

url(absolute = false, request_host = ENV['EPFWIKI_HOST'])

[Source]

        # File app/models/upload.rb, line 48
    48:   def url(absolute = false, request_host = ENV['EPFWIKI_HOST'])
    49:     s = "/uploads/#{self.new_filename}"
    50:     s = "http://#{request_host}#{s}" if absolute
    51:     s
    52:   end

[Validate]