Module: WillPaginate::NamedScope
- Defined in:
- lib/will_paginate/named_scope.rb
Overview
This is a feature backported from Rails 2.1 because of its usefullness not only with will_paginate, but in other aspects when managing complex conditions that you want to be reusable.
Defined Under Namespace
Modules: ClassMethods Classes: Scope
Class Method Summary collapse
-
.included(base) ⇒ Object
All subclasses of ActiveRecord::Base have two named_scopes: *
all
, which is similar to afind(:all)
query, and *scoped
, which allows for the creation of anonymous scopes, on the fly:.
Class Method Details
.included(base) ⇒ Object
All subclasses of ActiveRecord::Base have two named_scopes:
-
all
, which is similar to afind(:all)
query, and -
scoped
, which allows for the creation of anonymous scopes, on the fly:Shirt.scoped(:conditions => => ‘red’).scoped(:include => :washing_instructions)
These anonymous scopes tend to be useful when procedurally generating complex queries, where passing intermediate values (scopes) around as first-class objects is convenient.
15 16 17 18 19 20 21 |
# File 'lib/will_paginate/named_scope.rb', line 15 def self.included(base) base.class_eval do extend ClassMethods named_scope :all named_scope :scoped, lambda { |scope| scope } end end |