2019-08-14 09:48:44 +00:00
|
|
|
class AttachmentUploader < CarrierWave::Uploader::Base
|
|
|
|
include CarrierWave::MiniMagick
|
|
|
|
|
|
|
|
def store_dir
|
|
|
|
if Rails.env.test?
|
2019-10-02 13:56:09 +00:00
|
|
|
"#{Rails.root}/spec/support/uploads/attachments/#{model.class.to_s.underscore}/#{model.id}"
|
2019-08-14 09:48:44 +00:00
|
|
|
else
|
|
|
|
"uploads/attachments/#{model.class.to_s.underscore}/#{model.id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-20 08:47:26 +00:00
|
|
|
version :thumb, if: :image? do
|
|
|
|
process resize_to_fill: [280, 280]
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2019-10-20 08:47:26 +00:00
|
|
|
def image?(_new_file)
|
|
|
|
model.image?
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|