How to delete a model with a linked file

By default, I see that the carrier statement does not delete files associated with the model. How to do it?

+3
source share
4 answers

Carrierwave should delete files from S3 automatically for you. I just checked this in a Rails 3.1 application.

+2
source

You need to call

@image.destroy

not

@image.delete

Also use the refresh button on aws s3 panel

+1
source

, , , after_destroy, , .

class Model < ActiveRecord::Base
  after_destroy :delete_linked_file

  def delete_linked_file
    # Delete the linked file here
  end
end
0

, :

def delete_image_folder
    FileUtils.remove_dir(File.join(Rails.root, File.join( 'public' , file_name.store_dir)), :force => true)  
end

, Carrierwave, ( , )

0

Source: https://habr.com/ru/post/1785887/


All Articles