Question

I see by default carrierwave does not delete files linked to model. How to do it?

Was it helpful?

Solution

Carrierwave should remove the files from S3 automatically for you. I just tested this out on a Rails 3.1 app.

OTHER TIPS

You need to call

@image.destroy

not

@image.delete

Also use refresh button on aws s3 panel

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

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top