Skip to content

Instantly share code, notes, and snippets.

@rafaelp
Created October 12, 2011 15:18
Show Gist options
  • Save rafaelp/1281486 to your computer and use it in GitHub Desktop.
Save rafaelp/1281486 to your computer and use it in GitHub Desktop.
ActAsParanoid para Rails 3
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