I have model:
class UserWeight < ActiveRecord::Base
self.table_name = 'Weight'
scope :logged_between, lambda { |start_date, end_date|
where(weight_date: start_date.to_date...(end_date.to_date.end_of_day)) unless
start_date.nil? || end_date.nil?
}
# returns the sum of points
def total_points
self.class.Userweight
(UserWeight.blank?) ? 0 : UserWeight.inject(0) {|a, e| a + e.points}
end
end
Active record is returning collection of arrays. I want to access class method and do the sum in the instance method. Any idea how can i do that?
Thanks
Aucun commentaire:
Enregistrer un commentaire