Hi all, The subject sums up what I want to do in a nutshell. I have a collection of ActiveRecord objects (@galleries), and I want to generate from it another collection of arrays, each three elements long. This is simply so I can display preview pictures from all my @galleries in a three column table. What I want to end up with is something like this that I can iterate over to build my table: @collected -> [[gallery1, gallery2, gallery3], [gallery4, gallery5, gallery6]] etc I cannot for the life of me figure out a clean way to do it. Any hints or prods in the right direction would be great ;-) Many thanks, Dan -- Daniel Bye _ ASCII ribbon campaign ( ) - against HTML, vCards and X - proprietary attachments in e-mail / \
On 3/10/08, Daniel Bye <rails-tSCSLn4GjLmr5jXINAnWskB+6BGkLq7r@public.gmane.org> wrote:> What I want to end up with is something like this that I can iterate > over to build my table: > > @collected -> [[gallery1, gallery2, gallery3], > [gallery4, gallery5, gallery6]]Have a look at in_groups_of: http://api.rubyonrails.com/classes/ActiveSupport/CoreExtensions/Array/Grouping.html#M000636 -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
HI Dan Did you try "in_groups_of" http://www.noobkit.com/show/ruby/rails/rails-edge/activesupport-edge/activesupport/coreextensions/array/grouping/in_groups_of.html On Mon, 2008-03-10 at 19:42 +0000, Daniel Bye wrote:> Hi all, > > The subject sums up what I want to do in a nutshell. I have a collection > of ActiveRecord objects (@galleries), and I want to generate from it > another collection of arrays, each three elements long. This is simply > so I can display preview pictures from all my @galleries in a three > column table. > > What I want to end up with is something like this that I can iterate > over to build my table: > > @collected -> [[gallery1, gallery2, gallery3], > [gallery4, gallery5, gallery6]] > > etc > > I cannot for the life of me figure out a clean way to do it. Any > hints or prods in the right direction would be great ;-) > > Many thanks, > > Dan >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mon, Mar 10, 2008 at 04:26:50PM -0400, R T Ealey wrote:> HI Dan > > Did you try "in_groups_of" > http://www.noobkit.com/show/ruby/rails/rails-edge/activesupport-edge/ > activesupport/coreextensions/array/grouping/in_groups_of.htmlAha! That looks just the thing! Thanks (to Greg, too) for the pointer. I should have known Rails could do it for me! Cheers, Dan -- Daniel Bye _ ASCII ribbon campaign ( ) - against HTML, vCards and X - proprietary attachments in e-mail / \