Skip to content

Instantly share code, notes, and snippets.

@jrallison
Created February 5, 2011 20:47
Show Gist options
  • Save jrallison/812773 to your computer and use it in GitHub Desktop.
Save jrallison/812773 to your computer and use it in GitHub Desktop.
# Model
class Model < ActiveRecord::Base
default_scope where(:hidden => false)
def hide!
update_attributes!(:hidden => true)
end
end
# Controller
ModelController < ApplicationController
def destroy
Model.find(params[:id]).hide!
end
end
# Examples
Model.all # won't return hidden records
Model.where(:hidden => true).all # all hidden records
Model.unscoped.all # hidden and unhidden records
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment