Created
July 10, 2015 20:29
-
-
Save rubysolo/9bf315489f66db1b3143 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 HideDeleted | |
def hide_deleted | |
scope :existing, -> { where(deleted_at: nil) } | |
scope :deleted, -> { where('deleted_at IS NOT NULL') } | |
define_method :deleted? do | |
deleted_at.present? | |
end | |
define_method :destroy do | |
update_attribute(:deleted_at, Time.zone.now) | |
end | |
alias_method :destroy!, :destroy | |
end | |
end | |
ActiveRecord::Base.extend HideDeleted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment