Guest User

Untitled

a guest
Jun 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. module SoftDeletable
  2. extend ActiveSupport::Concern
  3.  
  4. included do
  5. default_scope { where(:deleted_at => nil) }
  6. scope :with_trashed, -> { unscope(where: :deleted_at) }
  7. scope :only_trashed, -> { unscope(where: :deleted_at).where.not(deleted_at: nil) }
  8. end
  9.  
  10. def destroy
  11. update(deleted_at: Time.now)
  12. end
  13.  
  14. def restore
  15. update(deleted_at: nil)
  16. end
  17. end
Add Comment
Please, Sign In to add comment