Class: PortraitUploader

Inherits:
CarrierWave::Uploader::Base
  • Object
show all
Includes:
CarrierWave::RMagick
Defined in:
app/uploaders/portrait_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.



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

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

#cropObject

version(:xxl) { process :resize_to_limit => [900, 900] }



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/uploaders/portrait_uploader.rb', line 34

def crop
  if model.crop_x.present?
    resize_to_limit(550, 550)
    manipulate! do |img|
      x = model.crop_x.to_i
      y = model.crop_y.to_i
      w = model.crop_w.to_i
      h = model.crop_h.to_i
      img.crop!(x, y, w, h)
    end
  end
end

#extension_white_listObject

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



49
50
51
# File 'app/uploaders/portrait_uploader.rb', line 49

def extension_white_list
  %w(jpg jpeg png)
end

#store_dirObject



5
6
7
8
# File 'app/uploaders/portrait_uploader.rb', line 5

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