diff --git a/app/models/asset.rb b/app/models/asset.rb index f31358cef..9af189c9c 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -68,6 +68,7 @@ class Asset < ActiveRecord::Base after_validation :filter_paperclip_errors # Needed because Paperclip validatates on creation after_initialize :filter_paperclip_errors, if: :new_record? + before_destroy :paperlip_delete, prepend: true attr_accessor :file_content, :file_info, :preview_cached @@ -238,14 +239,13 @@ class Asset < ActiveRecord::Base end end - def destroy + # Workaround for making Paperclip work with asset deletion + def paperlip_delete report_elements.destroy_all asset_text_datum.destroy if asset_text_datum.present? - # Nullify needed to force paperclip file deletion self.file = nil save - delete end # If team is provided, its space_taken