I have a player model and a game model set up with a HABTM.
I am trying to keep track of statistics for a player based on a hits
and misses, which the user marks when editing a game. When the game is
done editing an email is sent to the other team to confirm the game.
If it is confirmed the statistics should be updated on the site.
Here’s what I have:
@games = Game.find(:all)
for game in @games
if (found the right game through hashing)
flash[:notice] = “Thank you for validating the game.”
for team in self.teams
for player in team.players
for player in @game.players
self.update_attribute(:hit_percentage, (player.hit.to_f /
(player.hit.to_f + player.misses.to_f)) * 100) unless player.misses ==
self.update_attribute(:opp_percentage, player.points.to_f /
(player.hit.to_f + player.misses.to_f)) unless player.misses == 0
self.update_attribute(:hit, hit + 1)
I don’t think this is the correct way to represent each hit a player
has per game. How do I set it up like that?
Also how do I write a view to show the game with each player’s hits/