mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-02 21:51:51 +08:00
Merge pull request #532 from biosistemika/mz-SCI-1150
Fixed so that file deletion callbacks are triggered
This commit is contained in:
commit
2c78d10768
1 changed files with 10 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue