Reputation: 13952
I see by default carrierwave does not delete files linked to model. How to do it?
Upvotes: 3
Views: 2892
Reputation: 1657
Yes, You can do it like this
def delete_image_folder
FileUtils.remove_dir(File.join(Rails.root, File.join( 'public' , file_name.store_dir)), :force => true)
end
but just remember that if you changed the Carrierwave configuration root, you should take it into account (default is public so this code will work)
Upvotes: 0
Reputation: 653
You need to call
@image.destroy
not
@image.delete
Also use refresh button on aws s3 panel
Upvotes: 1
Reputation: 19723
Carrierwave should remove the files from S3 automatically for you. I just tested this out on a Rails 3.1 app.
Upvotes: 2
Reputation: 12165
I'm not familiar with carrierwave, but in general, hooking into the after_destroy
is likely what you want.
class Model < ActiveRecord::Base
after_destroy :delete_linked_file
def delete_linked_file
# Delete the linked file here
end
end
Upvotes: 0