app/uploaders/item_image_uploader.rb
require 'carrierwave/processing/mime_types'
class ItemImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::MimeTypes
process :set_content_type
process resize_to_limit: [740, 740]
if Rails.env.production? || Rails.env.staging?
storage :fog
else
storage :file
end
def store_dir
"uploads/item_image/#{mounted_as}/#{model.id}/"
end
def extension_white_list
%w(jpg gif png jpeg)
end
def filename
"#{secure_token}.#{file.extension}" if original_filename.present?
end
protected
def secure_token
var = :"@#{mounted_as}_secure_token"
model.instance_variable_get(var) || model.instance_variable_set(var, SecureRandom.uuid)
end
end