def actualiza_puntuacion(s) scores = Score.find(:all, :conditions => ["game_id = ?", self.id]) game = Game.find_by_id(self.id) total = 0.0 if s then total += s end for sc in scores do total += sc.score end if !(scores.length == 0) then if s total = total / (scores.length + 1) else total = total / scores.length end end game.total_score = total game.save end