Re: Generating a Grouped Output

Craig Demyanovich
Tue, 09 Oct 2007 02:38:25 -0000

Welcome, Martin.

The Rails API docs <http://api.rubyonrails.org> show that
ActiveRecord::Base#find<http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001004>can
take a :group option to do what you want. For example,

Game.find(:all, :group => "system")

Craig

On 10/8/07, Martin Austin
<mraustin82-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
>
>
> Hi all, first time poster.
>
> I am currently learning RoR, and have run into a snag.  I have a table
> called Games that has several fields, including title, desc, genre,
> system, etc.  What I am looking to do in a view is create an output
> that is grouped by system.  For example...
>
> Wii
> ... Wii Sports
> ... Metroid Prime 3
> Xbox 360
> ... Halo 3
>
> My first thought was to use nested for loops, looping through each
> unique system, and then looping through each game that matches that
> system, and while I know how to do this in PHP (using procedural
> code), I am struggling with how to contain my iteration objects within
> the controller, and access them only in the view.
>
> Any thoughts?  I hope I am explaining this well.
>
> Thanks,
>
> Martin
>
>
> >