Before I ask my question, I will give some context.
In my Rails 4 app, I have 3 models in question.
Clubs has_many Teams.
Teams belong_to Clubs
Clubs has_many Schedules.
Schedules belong_to Clubs.
The Relevant Columns for Teams in the Database:
:win(integer)
:loss(integer)
:tie(integer)
The Relevant Columns for Schedules in the Database:
:team1
:team2
The schedule object is supposed to show 2 teams versus each other. In the form for the schedule object, I will make
Club.teams available in 2 separate drop-down boxes, so the user can select :team1
and :team2
.
Upon the creation of a Schedule object, I'd like to make a toggle box available which you can click on later to state which team won the match.
Example Setup for the div of a Schedule Object:
Team 1 |(Box1)|(Box2)|(Box3)| Team 2
If Box1 is clicked for example, that would mean Team 1 won and I would automatically adjust the Win/Loss/Tie Columns in the Teams Table(Increase :win by 1 for Team 1 and increase :loss by 1 for Team 2). Box2 means tie and Box2 means Team 2 won. This will be done by ajax.
Finally, for my question, how do I associate :team1
and :team2
columns in the Schedule object with the appropriate Team objects in the Teams table in order to manipulate their columns with the toggle box?