Class: FileUploader

Inherits:
CarrierWave::Uploader::Base
  • Object
show all
Defined in:
app/uploaders/file_uploader.rb

Instance Method Summary collapse

Instance Method Details

#extension_white_listObject

Add a white list of extensions which are allowed to be uploaded. For images you might use something like this:



13
14
15
# File 'app/uploaders/file_uploader.rb', line 13

def extension_white_list
  %w(*)
end

#file_descObject

Description of file types acceptable for the uploader (passed to uploadify)



27
28
29
# File 'app/uploaders/file_uploader.rb', line 27

def file_desc
  "All Files (#{file_ext(',')})"
end

#file_ext(delimiter = ';') ⇒ Object

A string of file extensions acceptable for the uploader. (passed to uploadify)



20
21
22
# File 'app/uploaders/file_uploader.rb', line 20

def file_ext(delimiter= ';')
  extension_white_list.map {|ext| "*.#{ext}" }.join(delimiter)
end

#filenameObject



31
32
33
# File 'app/uploaders/file_uploader.rb', line 31

def filename
  super.presence || path.present? && path.split('/').last
end

#store_dirObject

Override the directory where uploaded files will be stored. This is a sensible default for uploaders that are meant to be mounted:



7
8
9
# File 'app/uploaders/file_uploader.rb', line 7

def store_dir
  "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end