Created
February 5, 2011 20:47
-
-
Save jrallison/812773 to your computer and use it in GitHub Desktop.
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
# 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