public
Created

Soft destroy library

  • Download Gist
soft_destroy.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.