DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Rails Named_scope
You got code like this
class User < ActiveRecord::Base
named_scope :school_names, :conditions => {:requirement_type => Type::SCHOOL_NAMES}
end
you would like to group the named_scope by 'name', you should add this code
named_scope :group, lambda { |str| { :group => str } }
use like this
User.school_names.group("name")






Comments
William Notowidagdo replied on Wed, 2007/08/15 - 11:34pm
Snippets Manager replied on Sat, 2009/11/07 - 10:22pm
named_scope :group, lambda { |*args| { :group => args.first || "name asc" } }Snippets Manager replied on Sat, 2009/11/07 - 10:22pm
named_scope :group, lambda { |*args| { :group => str || "name asc" } }