Created
September 3, 2012 00:18
-
-
Save sunny0425/3605827 to your computer and use it in GitHub Desktop.
delete old file(Example in http://guides.rubyonrails.org/active_record_validations_callbacks.html#callbacks-overview 18 Transaction Callbacks)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PictureFile < ActiveRecord::Base | |
attr_accessor :delete_file | |
after_destroy do |picture_file| | |
picture_file.delete_file = picture_file.filepath | |
end | |
after_commit do |picture_file| | |
if picture_file.delete_file && File.exist?(picture_file.delete_file) | |
File.delete(picture_file.delete_file) | |
picture_file.delete_file = nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment