add scope for each states

1
2
3
4
5
6
7
8
class User < ActiveRecord::Base
   STATES = [ 'pending', 'approved', 'denied' ]

   validates_inclusion_of :state, :in => STATES

   # Define a named scope for each state in STATES
   STATES.each { |s| named_scope s, :conditions => { :state => s } }
end

批量生成 named_scope.

    Posted by michael At December 03, 2008 15:50

请登录以发表评论。