Class: ImageUploader

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

Instance Method Summary collapse

Instance Method Details

#cache_dirObject

got this from stackoverflow.com/questions/9561641/carrierwave-temp-directory-set-to-uploads-tmp-folder without this all tmp files would go to /public/uploads/tmp which is not cool at all.



67
68
69
70
# File 'app/uploaders/image_uploader.rb', line 67

def cache_dir
  # should return path to cache dir
  Rails.root.join 'tmp/uploads'
end

#extension_white_listObject

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



55
56
57
# File 'app/uploaders/image_uploader.rb', line 55

def extension_white_list
  %w(jpg jpeg gif png)
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:



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

def store_dir
  # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"  --- that was the suggested one
  "system/images/#{model.class.to_s.underscore}/#{model.id}"
end