2017-06-02 14:30:26 +02:00
|
|
|
class AttestationUploader < BaseUploader
|
|
|
|
def root
|
2018-03-06 13:44:29 +01:00
|
|
|
Rails.root.join("public")
|
2017-06-02 14:30:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Choose what kind of storage to use for this uploader:
|
2019-07-31 12:25:40 +02:00
|
|
|
if Rails.application.secrets.fog[:enabled]
|
2017-06-02 14:30:26 +02:00
|
|
|
storage :fog
|
|
|
|
else
|
|
|
|
storage :file
|
|
|
|
end
|
|
|
|
|
|
|
|
# Override the directory where uploaded files will be stored.
|
|
|
|
# This is a sensible default for uploaders that are meant to be mounted:
|
|
|
|
def store_dir
|
2019-07-31 12:25:40 +02:00
|
|
|
if !Rails.application.secrets.fog[:enabled]
|
2017-06-02 14:30:26 +02:00
|
|
|
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
|
|
|
end
|
|
|
|
end
|
2017-10-18 14:29:12 +02:00
|
|
|
|
|
|
|
def filename
|
2019-08-27 17:42:52 +02:00
|
|
|
if file.present?
|
|
|
|
"attestation-#{secure_token}.pdf"
|
|
|
|
end
|
2017-10-18 14:29:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def secure_token
|
|
|
|
model.content_secure_token ||= SecureRandom.uuid
|
|
|
|
end
|
2017-06-02 14:30:26 +02:00
|
|
|
end
|