I’m making a site that will display statistics. For my question I have
two models, a School and a Team.
A team has an integer, games.
What is the best way to output for each school, the total number of
games for all the school’s teams?
I’m making a site that will display statistics. For my question I have
two models, a School and a Team.
A team has an integer, games.
What is the best way to output for each school, the total number of
games for all the school’s teams?
edberner wrote:
I’m making a site that will display statistics. For my question I have
two models, a School and a Team.A team has an integer, games.
What is the best way to output for each school, the total number of
games for all the school’s teams?
If this is a database or model question, sufficient use of has_many
directives
will enable a line like school.team.map{|t| [t.name, t.games.count] }
If it’s a view question, the answer is some combination if
This worked.
for school in @schools
for team in school.teams
school.games += team.games
end
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs