Class: ImageUploader

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

Instance Method Summary collapse

Instance Method Details

#duplicate_from(other_uploader) ⇒ Object


45
46
47
48
49
50
51
52
# File 'app/uploaders/image_uploader.rb', line 45

def duplicate_from(other_uploader)
  case other_uploader.send(:storage).class.name
  when 'CarrierWave::Storage::File'
    cache!(File.new(other_uploader.file.path))
  when 'CarrierWave::Storage::Fog', 'CarrierWave::Storage::AWS'
    download!(other_uploader.url)
  end
end

#extension_whitelistObject

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


41
42
43
# File 'app/uploaders/image_uploader.rb', line 41

def extension_whitelist
  %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:


10
11
12
# File 'app/uploaders/image_uploader.rb', line 10

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