Created
October 12, 2011 15:18
-
-
Save rafaelp/1281486 to your computer and use it in GitHub Desktop.
ActAsParanoid para Rails 3
This file contains 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 ActsAsParanoid | |
def acts_as_paranoid | |
default_scope where(:deleted_at => nil) | |
include InstanceMethods | |
end | |
module InstanceMethods | |
def destroy | |
run_callbacks(:destroy) do | |
if persisted? | |
self.update_attribute(:deleted_at, Time.now.utc) | |
end | |
@destroyed = true | |
freeze | |
end | |
end | |
end | |
end | |
ActiveRecord::Base.extend ActsAsParanoid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment