1

In a view, I get an array of objects. I want to have a three column table that will be filled with an attribute of those objects. So, if my list has 5 objects, my table will have two rows: the first row will contain three cells, and the second row 2 cells.

How do I iterate over that list in order to accomplish this?

3
  • This is one big long non-sequitur. How do you get from 5 objects to only two rows? Commented Mar 22, 2012 at 5:39
  • 5 objects and I have 3 objects per row (3 columns) Commented Mar 22, 2012 at 5:41
  • It would be better to post what you have attempted so far and tell us where you're stuck. Here is a hint..you will want to start a new row when n % 3 is 0. 'n' being your current position in the array. Commented Mar 22, 2012 at 5:46

1 Answer 1

1

If you really want to use tables and just iterate over your array you could use each_slice and go over the returned arrays, like your_array.each_slice(3)

But you could also not use tables, use some divs for example, and iterate over your big (5 objects) array and style the divs so that they fit 3 in a row.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.