RailsCasts Pro episodes are now free!
Learn more or hide this
Note: there's a lot more to the named_scope method which I didn't cover, please see the links below for additional info.
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