# Render collection with index

**URL:** <https://www.ruby-forum.com/t/render-collection-with-index/85943>\
**Category:** Rails\
**Created:** [February 18, 2007, 12:34am UTC](https://www.ruby-forum.com/t/render-collection-with-index/85943 "2007-02-18T00:34:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [February 18, 2007, 12:34am UTC](https://www.ruby-forum.com/t/render-collection-with-index/85943/1 "2007-02-18T00:34:38Z")

</div>

Is there any method for getting the current iteration (for changing row  
colors) in the category partial?

\<%=render(:partial =\> “category”, :collection =\> @categories)%\>

thanks,  
andy

–  
Andrew S.

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [February 18, 2007, 12:41am UTC](https://www.ruby-forum.com/t/render-collection-with-index/85943/2 "2007-02-18T00:41:39Z")

</div>

Andrew :

> Is there any method for getting the current iteration (for changing row  
> colors) in the category partial?
> 
> \<%=render(:partial =\> “category”, :collection =\> @categories)%\>

Use the variable category\_counter in your partial.

– Jean-François.

–  
Ruby ( [http://www.rubyfrance.org](http://www.rubyfrance.org) ) on Rails ( [http://www.railsfrance.org](http://www.railsfrance.org)  
)

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [February 18, 2007, 12:47am UTC](https://www.ruby-forum.com/t/render-collection-with-index/85943/3 "2007-02-18T00:47:39Z")

</div>

> Use the variable category\_counter in your partial.
> 
> – Jean-FranÃ§ois.

Thanks so much! I knew there had to be something there…just couldn’t  
find  
it.

–  
Andrew S.

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [February 18, 2007, 12:56am UTC](https://www.ruby-forum.com/t/render-collection-with-index/85943/4 "2007-02-18T00:56:41Z")

</div>

On 2/17/07, Aaron [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Aaron

That is cool. I wish I new that before I wrote my row\_class method. 🙂

–  
Andrew S.

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [February 18, 2007, 12:49am UTC](https://www.ruby-forum.com/t/render-collection-with-index/85943/5 "2007-02-18T00:49:40Z")

</div>

Andy,

The cycle method is a great way to do this. Here is an example:

Then just style ListLine0 and ListLine1.

Aaron

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [February 18, 2007, 12:57am UTC](https://www.ruby-forum.com/t/render-collection-with-index/85943/6 "2007-02-18T00:57:41Z")

</div>

> That is cool. I wish I new that before I wrote my row\_class method. 🙂

Also wish I could spell… 😉

sorry for the extra noise.

–  
Andrew S.
