Merge pull request #532 from biosistemika/mz-SCI-1150

Fixed so that file deletion callbacks are triggered
This commit is contained in:
mz3944 2017-04-07 15:18:43 +02:00 committed by GitHub
commit 2c78d10768

View file

@ -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 :paperclip_delete, prepend: true
attr_accessor :file_content, :file_info, :preview_cached
@ -238,13 +239,20 @@ class Asset < ActiveRecord::Base
end
end
def destroy
# Workaround for making Paperclip work with asset deletion (might be because
# of how the asset models are implemented)
def paperclip_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
end
def destroy
super()
# Needed, otherwise the object isn't deleted, because of how the asset
# models are implemented
delete
end