Technology Musings

July 02, 2008

Features / named_scope is really cool


Rails 2.1.0 has, among other things, one very cool feature - named scoping.

class Whatever < ActiveRecord::Base
  named_scope :active, :conditions => { :active => true }
end  #yields all active whatevers #only runs find() on active whatevers

You can even have parameters that get passed in through anonymous functions. It's a very powerful mechanism, and makes everything much more beautiful.  Learn more here.