On Oct 24, 12:28 pm, Graham Dawe
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> Hi,
>
> I am in the process of building a league management app.
>
> I currently have seasons, leagues and teams that are all working fine. I
> can create a new season, add the leagues that are playing in it and the
> teams that play within each of the leagues.
>
> What I now want to do is create fixtures for the teams. I have generated
> a fixtures model and associated it with teams (has_many :teams) and
> teams with fixtures (has_many :fixtures).
>
> What I would like to be able to do when a user sets up the fixtures he
> can just press a submit button that will generate all of the fixtures
> between the teams (each team plays the other twice). I have been able,
> using .permutations (get_team_combinations >
Team.names.permutation(2).to_a) to generate an array of fixtures but I
> am stumped as
> to how it would be possible to have each of these entries in the array
> saved as a fixture in the database.
well rather than permuting the names, i''d work with the teams
directly, i.e.
Team.all.permutation(2) do |team1, team2|
Fixture.create(...)
end
and then in that block create the fixture object for team1 versus team
2. Note that if you had teams a,b,c then you''ll get both a,b and b,a
as 2 different permutations. This might be what you want (e.g. if in a
season each pair meets twice, swapping who is the home team and who is
the away team), but if it isn''t then try using combination instead of
permutation
Fred
>
> Anybody got any ideas how this is possible or an alternative way of
> generating the fixtures?
>
> Thanks for help in advance! :)
>
> --
> Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.