Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Acts
- module Paranoid
- def acts_as_paranoid
- named_scope :not_deleted, :conditions => ["(deleted_at < ? OR deleted_at is null)", Time.now]
- class << self
- alias_method :find_with_deleted, :find
- end
- alias_method :destroy!, :destroy
- extend ClassMethods
- include InstanceMethods
- end
- end
- module ClassMethods
- def find(*args)
- not_deleted.find_with_deleted(*args)
- end
- end
- module InstanceMethods
- def destroy
- update_attribute(:deleted_at, Time.now)
- end
- end
- end
- ActiveRecord::Base.extend(Acts::Paranoid)
Add Comment
Please, Sign In to add comment