Skip to content

Instantly share code, notes, and snippets.

@jqr
Created November 13, 2009 16:05
Show Gist options
  • Save jqr/233925 to your computer and use it in GitHub Desktop.
Save jqr/233925 to your computer and use it in GitHub Desktop.
class ActiveRecord::Base
def self.soft_destroyable(column = :destroyed_at)
define_method(:destroy_without_callbacks) do
update_attribute(column, Time.now)
end
named_scope :destroyed, :conditions => ["NOT #{column} IS NULL", column]
named_scope :not_destroyed, :conditions => ["#{column} IS NULL", column]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment