# Making a simple table grid

**URL:** <https://www.ruby-forum.com/t/making-a-simple-table-grid/106126>\
**Category:** Rails\
**Created:** [June 6, 2007, 5:53pm UTC](https://www.ruby-forum.com/t/making-a-simple-table-grid/106126 "2007-06-06T17:53:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![revanche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ac91a4/32.png) [@revanche](https://www.ruby-forum.com/u/revanche)\
**Post date:** [June 6, 2007, 5:53pm UTC](https://www.ruby-forum.com/t/making-a-simple-table-grid/106126/1 "2007-06-06T17:53:55Z")

</div>

I searched around the forums for an answer to this question, but most  
seemed to deal with structures and functionality that are a little  
farther beyond what I am looking for.

Given that a data set (say, @results), how would you display those  
results in a simple grid that is 5 items across and as many down as it  
needs to be.

Thanks in advance for help with what seems to be an elusive but simple  
question. 🙂

---

<div class="post-metadata">

**Author:** ![revanche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ac91a4/32.png) [@revanche](https://www.ruby-forum.com/u/revanche)\
**Post date:** [June 6, 2007, 6:09pm UTC](https://www.ruby-forum.com/t/making-a-simple-table-grid/106126/2 "2007-06-06T18:09:59Z")

</div>

On Jun 6, 5:53 pm, Neil H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I searched around the forums for an answer to this question, but most  
> seemed to deal with structures and functionality that are a little  
> farther beyond what I am looking for.
> 
> Given that a data set (say, @results), how would you display those  
> results in a simple grid that is 5 items across and as many down as it  
> needs to be.
> 
> Thanks in advance for help with what seems to be an elusive but simple  
> question. 🙂

Without looking into the problem, I think I would draw 5 tables. Like  
so:

split\_count = @result.size / 5  
split\_counter = 0

@result.each do |result|  
\<% split\_counter++ %\>

# make a table and then begin a new table after split\_counter has

reached split\_count.

\<% split\_counter = 0 if split\_counter == split\_count %\>  
end

Beware when result.size is \< 5 of course.

just from the top of my head, there might very well be a better  
solution 🙂

---

<div class="post-metadata">

**Author:** ![revanche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ac91a4/32.png) [@revanche](https://www.ruby-forum.com/u/revanche)\
**Post date:** [June 6, 2007, 6:46pm UTC](https://www.ruby-forum.com/t/making-a-simple-table-grid/106126/3 "2007-06-06T18:46:37Z")

</div>

Neil H. wrote:

> I searched around the forums for an answer to this question, but most  
> seemed to deal with structures and functionality that are a little  
> farther beyond what I am looking for.
> 
> Given that a data set (say, @results), how would you display those  
> results in a simple grid that is 5 items across and as many down as it  
> needs to be.
> 
> Thanks in advance for help with what seems to be an elusive but simple  
> question. 🙂

Sounds like you want in\_groups\_of.

See this thread for more info:

[http://www.ruby-forum.com/topic/73779#108452](http://www.ruby-forum.com/topic/73779#108452)
