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