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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Maybe Matching Threads
- How can I improve a Ruby on Rails code that hast a lot of SQL as strings?
- find_by_sql preformance problems when ordering data
- Variable Importance - Random Forest
- Appropriate measure of correlation with 'zero-inflated' data?
- Random Forests: Predictor importance for Regression Trees