# Adding a action to a player

**URL:** <https://www.ruby-forum.com/t/adding-a-action-to-a-player/135154>\
**Category:** Rails\
**Created:** [April 18, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/adding-a-action-to-a-player/135154 "2008-04-18T16:20:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![edberner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f9ae1b/32.png) [@edberner](https://www.ruby-forum.com/u/edberner)\
**Post date:** [April 18, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/adding-a-action-to-a-player/135154/1 "2008-04-18T16:20:02Z")

</div>

When I create a new game I have this  
10.times { @game.rounds.create }  
for round in @game.rounds  
6.times { round.add\_actions }  
end

Here are my specifications.  
A game has and belongs to many teams  
There are two teams per game.  
There are three players on a team.  
Each game can have any number of actions (which belong to a round),  
but % 6 will always = 0, because they are added in 6s.

This does not work:  
for round in @game.rounds  
3.times { @game.teams[0].players \<\< round.actions.create }  
3.times { @game.teams[1].players \<\< round.actions.create }  
end  
I am trying to get it so each action is linked with a player. Also, so  
each team is linked to all the actions of each player, so I can track  
how many times a player has done an action. My problem is I cannot get  
the actions to link to the player and have the team track how many  
times an action has been committed, per game.

---

<div class="post-metadata">

**Author:** ![edberner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f9ae1b/32.png) [@edberner](https://www.ruby-forum.com/u/edberner)\
**Post date:** [April 18, 2008, 4:24pm UTC](https://www.ruby-forum.com/t/adding-a-action-to-a-player/135154/2 "2008-04-18T16:24:08Z")

</div>

That was stupid.  
It’s just  
10.times { @game.rounds.create }  
for round in @game.rounds  
for player in @game.teams[0].players  
player.actions \<\< round.actions.create  
end  
for player in @game.teams[1].players  
player.actions \<\< round.actions.create  
end  
end

---

<div class="post-metadata">

**Author:** ![edberner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f9ae1b/32.png) [@edberner](https://www.ruby-forum.com/u/edberner)\
**Post date:** [April 18, 2008, 4:29pm UTC](https://www.ruby-forum.com/t/adding-a-action-to-a-player/135154/3 "2008-04-18T16:29:28Z")

</div>

Still though, how do I make it so that a team stores how many times  
each player has committed actions per game?
