Shrine isn't automatically deleting dynamic derivatives, because it doesn't know where they were uploaded, since the destination storage is configurable.
You'll need to delete them manually after the record is deleted, for example:
[[800, 800], [500, 500], [300, 300], ...].each do |(width, height)|
photo.file.derivation(:thumbnail, width, height).delete
end
You can also send that to a background job, for example:
DeleteDynamicDerivatives.perform_async(
photo.file.shrine_class,
photo.file.to_json,
[[:thumbnail, 800, 800], [:thumbnail, 500, 500], [:thumbnail, 300, 300], ...],
)
class DeleteDynamicDerivatives
include Sidekiq::Worker
def perform(shrine_class, file_data, derivations)
shrine_class = Object.const_get(shrine_class)
file = shrine_class.uploaded_file(file_data)
derivations.each do |args|
file.derivation(*args).delete
end
end
end
I would like to make it automatic at some point, but at the moment I don't know how.