Plugins - ScopedProxy

StarAdd to favorites

ScopedProxy uses with_scope and proxy objects to make it easy to find and count different types of records.

Examples

  class Person < ActiveRecord::Base
   scoped_proxy :minor, :conditions => 'age <= 17'
   scoped_proxy :adult, :conditions => 'age >= 18'
   scoped_proxy :old, :conditions => 'age >= 70'
   scoped_proxy :male, :conditions => 'gender = "male"'
   scoped_proxy :female, :conditions => 'gender = "female"'

   scoped_proxy :single, :conditions => 'married = 0'
   scoped_proxy :married, :conditions => 'married = 1'
  end

  Person.adult.find :all
  Person.single.find :all

They can also be chained together.

  Person.single.female.find :all
  Person.old.male.count

Jack Christensen

http://www.jackchristensen.com/article/4/scopedproxy-plugin-for-ruby-on-rails

  • Currently 5.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Model

Tags

Comments

Add a comment

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?