Skip to content

Instantly share code, notes, and snippets.

@lukaskonarovsky
Created December 2, 2011 11:38
Show Gist options
  • Save lukaskonarovsky/1422940 to your computer and use it in GitHub Desktop.
Save lukaskonarovsky/1422940 to your computer and use it in GitHub Desktop.
# encoding: utf-8
module Trashable
extend ActiveSupport::Concern
included do
define_model_callbacks :trash, :only => [ :after, :before ]
default_scope where('trashed_at IS NULL')
scope :trashed, where('trashed_at IS NOT NULL')
end
def trash
run_callbacks :trash do
update_attribute :trashed_at, DateTime.now
end
end
def restore_from_trash
update_attribute :trashed_at, nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment