class Product < ActiveRecord::Base
belongs_to :category
scope :discontinued, where(:discontinued => true)
# scope :cheaper_than, lambda {|price| where("price < ?", price)}
def self.cheaper_than(price)
where("products.price < ?", price)
end
scope :cheap, cheaper_than(5)
endclass Category < ActiveRecord::Base has_many :products scope :with_cheap_products, joins(:products) & Product.cheap end
