Sum method

Hello

in my Faq model i added a method
def calculate_score
score_faq = 0
self.votes.each do |t|
score_faq += t.score
end
self.score= score_faq
end

this method working well but i would like to use sum
def calculate_score
self.score = self.votes.sum(&:score)
end

But this new method was not working

Can u explain me why ?

Thanks

Bolo wrote:

i would like to use sum
def calculate_score
self.score = self.votes.sum(&:score)
end

But this new method was not working

Can u explain me why ?

Try:

self.votes.sum(‘score’)

(For future reference, it is useful if you can post the actual error
message that you get, rather than just telling us that it doesn’t
work.)

Chris