Guest User

Untitled

a guest
Feb 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. module Acts
  2. module Paranoid
  3. def acts_as_paranoid
  4. named_scope :not_deleted, :conditions => ["(deleted_at < ? OR deleted_at is null)", Time.now]
  5. class << self
  6. alias_method :find_with_deleted, :find
  7. end
  8. alias_method :destroy!, :destroy
  9. extend ClassMethods
  10. include InstanceMethods
  11. end
  12. end
  13. module ClassMethods
  14. def find(*args)
  15. not_deleted.find_with_deleted(*args)
  16. end
  17. end
  18. module InstanceMethods
  19. def destroy
  20. update_attribute(:deleted_at, Time.now)
  21. end
  22. end
  23. end
  24. ActiveRecord::Base.extend(Acts::Paranoid)
Add Comment
Please, Sign In to add comment