Class: FileUploader
- Inherits:
-
CarrierWave::Uploader::Base
- Object
- CarrierWave::Uploader::Base
- FileUploader
- Defined in:
- app/uploaders/file_uploader.rb
Instance Method Summary collapse
-
#extension_white_list ⇒ Object
Add a white list of extensions which are allowed to be uploaded.
-
#file_desc ⇒ Object
Description of file types acceptable for the uploader (passed to uploadify).
-
#file_ext(delimiter = ';') ⇒ Object
A string of file extensions acceptable for the uploader.
- #filename ⇒ Object
-
#store_dir ⇒ Object
Override the directory where uploaded files will be stored.
Instance Method Details
#extension_white_list ⇒ Object
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_desc ⇒ Object
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 |
#filename ⇒ Object
31 32 33 |
# File 'app/uploaders/file_uploader.rb', line 31 def filename super.presence || path.present? && path.split('/').last end |
#store_dir ⇒ Object
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 |