04 Mar '12, 4am

Railscasts - named_scope:

class Product < ActiveRecord::Base belongs_to :category named_scope :cheap, :conditions => { :price => 0..5 } named_scope :recent, lambda { |*args| {:conditions => ["released_at > ?", (args.first || 2.weeks.ago)]} } named_scope :visible, :include => :category, :conditions => { 'categories.hidden' => false } end

Full article: http://railscasts.com/episodes/108-named-scope

Tweets