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? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 <dl> or <table> tags, to display each school, team, and game count. So nobody here can tell what the "best" way is. Try asking a more specific question! -- Phlip --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This worked.
for school in @schools
     for team in school.teams
       school.games += team.games
     end
   end
On Apr 5, 9:57 pm, Phlip
<phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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
<dl> or <table> tags,
> to display each school, team, and game count.
>
> So nobody here can tell what the "best" way is. Try asking a more
specific question!
>
> --
>    Phlip
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@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
-~----------~----~----~----~------~----~------~--~---