Created
December 2, 2011 11:38
-
-
Save lukaskonarovsky/1422940 to your computer and use it in GitHub Desktop.
This file contains 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
# 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