When I delete an uploaded file using CarrierWave and Mongoid it remove the file but leave emty folders.
/files/:user_id/images/:file_id/ ['image.png', 'content_image.png', 'thumb_image.png']
I want the :file_id
folder to also be removed when the file is deleted. Is there a way to do this?
I've solved this with this:
before_destroy :remember_id
after_destroy :remove_id_directory
protected
def remember_id
@id = id
end
def remove_id_directory
FileUtils.remove_dir("#{Rails.root}/path/to/folder/#{@id}", :force => true)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With