Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module SoftDeletable
- extend ActiveSupport::Concern
- included do
- default_scope { where(:deleted_at => nil) }
- scope :with_trashed, -> { unscope(where: :deleted_at) }
- scope :only_trashed, -> { unscope(where: :deleted_at).where.not(deleted_at: nil) }
- end
- def destroy
- update(deleted_at: Time.now)
- end
- def restore
- update(deleted_at: nil)
- end
- end
Add Comment
Please, Sign In to add comment