[英]How delete model with linked file
我看到默認情況下,carrierwave不會刪除鏈接到模型的文件。 怎么做?
Carrierwave應自動從S3中刪除文件。 我剛剛在Rails 3.1應用程序上測試了這個。
你需要打電話
@image.destroy
不
@image.delete
還可以在aws s3面板上使用刷新按鈕
是的,你可以這樣做
def delete_image_folder
FileUtils.remove_dir(File.join(Rails.root, File.join( 'public' , file_name.store_dir)), :force => true)
end
但請記住,如果您更改了Carrierwave配置根,則應將其考慮在內(默認為公共,因此此代碼可以正常工作)
我不熟悉carrierwave,但總的來說,掛入after_destroy
可能就是你想要的。
class Model < ActiveRecord::Base
after_destroy :delete_linked_file
def delete_linked_file
# Delete the linked file here
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.