Created
July 11, 2016 15:11
-
-
Save ivobenedito/cff6ad05a0b7dcd35ebfd536402fa3f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Trashable | |
| extend ActiveSupport::Concern | |
| included do | |
| default_scope { where(deleted_at: nil) } | |
| end | |
| module ClassMethods | |
| def trashed | |
| unscope(where: :deleted_at).where.not(deleted_at: nil) | |
| end | |
| def with_trashed | |
| unscope(where: :deleted_at) | |
| end | |
| end | |
| def trashed? | |
| deleted_at.present? | |
| end | |
| def trash! | |
| update(deleted_at: Time.now) | |
| end | |
| def restore! | |
| update(deleted_at: nil) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment