Grouping arrays in the View

I remember reading something awhile back about an easy way to work with
object arrays in views. Say I want to arrange 20 images objects in rows
of 3. I have a collection of @users, where each user has a
user.thumbnail_url image. Is there some way to split these up so that
they can be easily parsed in rows of three?

Thanks,

Nathan

I think your best option would to make a helper for it. Make one helper
that accepts the entire array and breaks it up into chunks of three,
which
passes it to another helper that actually displays the 3 images for you.

If the problem is getting the actual data out, array has a method called
collect which can be used to call the same method on multiple objects in
an
array, so you could do something like @users.collect{|user|
user.thumbnail_url} That will give you an array of all of their image
urls.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs