Skip to content

Instantly share code, notes, and snippets.

@slant
Created March 16, 2011 07:15
Show Gist options
  • Select an option

  • Save slant/872136 to your computer and use it in GitHub Desktop.

Select an option

Save slant/872136 to your computer and use it in GitHub Desktop.
# View users/index
<%= User.where(:archived => true).each { |u| user.name } %>
>> User.all.size
=> 70
>> User.unscoped.all.size
=> 75
# User Controller
def index
@users = User.where(:archived => true)
end
# users/index View
<%= @users.each { |u| user.name } %>
# User Model
def self.archived
where(:archived => true)
end
# User Controller
def index
@users = User.archived
end
# users/index View
<%= @users.each { |u| user.name } %>
scope :archived, where( :archived => true )
# User Controller
def index
@users = User.archived
end
# users/index View
<%= @users.each { |u| user.name } %>
scope :has_role, lambda do |role|
where( :role => role )
end
@users = User.has_role('admin')
default_scope where(:archived => false)
User.where(:archived => true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment