Forum: Ruby on Rails Working with in_groups_of

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rob S. (Guest)
on 2009-03-08 23:57
I'm trying to build a table out using in groups of, but I'd also like to
be able to customize the first and last rows.

Apart from the actual formatting, is there an efficient way to figure
out how many total groups there are and what group the iteration is in?
Greg D. (Guest)
on 2009-03-09 19:28
(Received via mailing list)
On Sun, Mar 8, 2009 at 4:57 PM, Rob Scott
<removed_email_address@domain.invalid> wrote:
>
> I'm trying to build a table out using in groups of, but I'd also like to
> be able to customize the first and last rows.
>
> Apart from the actual formatting, is there an efficient way to figure
> out how many total groups there are and what group the iteration is in?

users = User.find(:all).in_groups_of( 3 )

users.first and users.last will be the first and last groups
respectively.

users.size will be the total groups of users.

And then going forward you can figure all this out on your own using
users.methods.sort.. like seeing that users.class is an Array will let
you know you can use anything from the Array class on your users
collection.


--
Greg D.
http://destiney.com/
This topic is locked and can not be replied to.