Skip to content

Instantly share code, notes, and snippets.

@mufasa71
Created July 29, 2013 08:38
Show Gist options
  • Save mufasa71/6102980 to your computer and use it in GitHub Desktop.
Save mufasa71/6102980 to your computer and use it in GitHub Desktop.
class Page < ActiveRecord::Base
attr_accessible :body, :name, :slug, :image, :destroyed_at
include DestroyedAt
has_attached_file :image
before_destroy :make_backup, prepend: true
before_restore :revert_image
private
def make_backup
self.image_backup = [self.image_file_name, self.image_content_type, self.image_file_size, self.image_updated_at].join(',')
end
def revert_image
image_meta = self.image_backup.split(',')
self.image_file_name = image_meta[0]
self.image_content_type = image_meta[1]
self.image_file_size = image_meta[2].to_i
self.image_updated_at = Time.parse(image_meta[3])
self.image_backup = nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment