# For Loop

**URL:** <https://www.ruby-forum.com/t/for-loop/122128>\
**Category:** Rails\
**Created:** [December 4, 2007, 8:49pm UTC](https://www.ruby-forum.com/t/for-loop/122128 "2007-12-04T20:49:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 4, 2007, 8:49pm UTC](https://www.ruby-forum.com/t/for-loop/122128/1 "2007-12-04T20:49:41Z")

</div>

If I have a loop, let’s say:

\<% for user in @users %\>

 \<%= link\_to "#{user.his\_uid}", :action =\> 'show', :id =\> user %\> \<%= link\_to "#{user.his\_uid}", :action =\> 'show', :id =\> user %\> \<% end %\>

How can I get the second #{user.his\_uid} to be the second object in  
the list? Is there a method for this (object.next) or a special way of  
making two columns tables?

Thanks in advance,  
LP

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 4, 2007, 9:47pm UTC](https://www.ruby-forum.com/t/for-loop/122128/2 "2007-12-04T21:47:54Z")

</div>

On Dec 4, 2007 1:48 PM, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<% end %\>
> 
> How can I get the second #{user.his\_uid} to be the second object in  
> the list? Is there a method for this (object.next) or a special way of  
> making two columns tables?

Have a look at in\_groups\_of:

[http://api.rubyonrails.com/classes/ActiveSupport/CoreExtensions/Array/Grouping.html](http://api.rubyonrails.com/classes/ActiveSupport/CoreExtensions/Array/Grouping.html)

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 5, 2007, 12:38am UTC](https://www.ruby-forum.com/t/for-loop/122128/3 "2007-12-05T00:38:43Z")

</div>

Are you after something like this?

\<% for user in @users %\> \<%= link\_to user.his\_uid, :action =\> 'show', :id =\> user %\> \<% end %\>

–  
Ryan B.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 7, 2007, 8:58am UTC](https://www.ruby-forum.com/t/for-loop/122128/4 "2007-12-07T08:58:44Z")

</div>

Thank you Greg! Exactly what I needed.
