Skip to content

Instantly share code, notes, and snippets.

@sunny0425
Created September 3, 2012 00:18
Show Gist options
  • Save sunny0425/3605827 to your computer and use it in GitHub Desktop.
Save sunny0425/3605827 to your computer and use it in GitHub Desktop.
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