Written by Sean Behan on Sun Jun 17th 2012

You can easily chain scopes together in your models. class Article < ActiveRecord::Base scope :ordered, order('position ASC') scope :published, ordered.where('published = ?', true) scope :for_homepage, published.limit(3) end

Article.for_homepage.to_sql

=> SELECT \"articles\".* FROM \"articles\" WHERE (published = 't') ORDER BY position LIMIT 3


Tagged with..
#active record #models #named scopes #scopes #Ruby on Rails

Just finishing up brewing up some fresh ground comments...