1
は、次のコードを考えるとどのように乾燥させるために:named_scope拡張
named_scope :by_order, :order => 'priority ASC' do
def total_points
self.sum('point_value')
end
end
named_scope :required, :conditions => ['bonus = ?', false] do
def total_points
self.sum('point_value')
end
end
named_scope :bonus, :conditions => ['bonus = ?', true] do
def total_points
self.sum('point_value')
end
end
をどのようにドライアップを繰り返しtotal_points方法でしょうか?
環境:Railsの2.3.11
独立したnamed_scopeをチェーン化することができます。 – apneadiving
あなたは他のスコープにチェーンすることができる 'total_points'というメソッドを作ることができます – bor1s
それらは確かにかなり良い、簡単なアプローチです! – keruilin