Answer the question
In order to leave comments, you need to log in
How to rename a file already uploaded with carrierwave?
Hello
It is necessary to rename existing files uploaded with carrierwave.
In the loader I changed the filename method
to be:
def filename
"photo.jpg" if original_filename
end
def filename
"#{secure_token}.jpg" if original_filename
end
protected
def secure_token
var = :"@#{mounted_as}_secure_token"
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.uuid)
end
RoutePointPhoto.all.each { |i| i.photo.recreate_versions! }
Answer the question
In order to leave comments, you need to log in
After you have changed the filename method , run through the rake task or from the console
RoutePointPhoto.all.each do |p|
p.photo.recreate_versions!
p.save!
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question