Created
October 16, 2011 15:12
-
-
Save Nakort/1291014 to your computer and use it in GitHub Desktop.
Soft destroy library
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
# Place this in your lib folder | |
# Include it in your model | |
# Add a migration with a deleted_at timestamp column for that model | |
# and voila your records are now logically destroyed. | |
# | |
module SoftDestroy | |
extend ActiveSupport::Concern | |
included do | |
default_scope where(:deleted_at => nil) | |
end | |
module InstanceMethods | |
def destroy | |
self.deleted_at = Time.now | |
self.save | |
true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment