I have an array of Rails ActiveRecord models in which I need to group
by name and then sort by topic. For instance the initial array may
look like this (hopefully formatting comes out correctly):
Name Topic
News Politics
Sports Soccer
Finance Stocks
Finance Bonds
News World
News Entertainment
I will need to display the list as follows:
Name Topic
Finance Bonds
Stocks
News Entertainment
Politics
World
Sports Soccer
As you can see, we only display the name on the first entry of that
name. Sure, I can simply sort a one-dimensional array of these
objects and place the logic into the presentation such that it checks
if the name it is processing now differs from the last name. But that
didn''t see so clean. Is there a better Ruby way in doing this?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Is your Topic not a proper ActiveRecord model? It seems like you have a one-to-many relationship. If you have Topic and, say, SubTopics, you should just traverse the Topics first, then their SubTopics. You can even get all the data in one query with :include. -- Posted via http://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-/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 -~----------~----~----~----~------~----~------~--~---