Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Soft destroy library
# 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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.