# Way to alternate styles/classes?

**URL:** <https://www.ruby-forum.com/t/way-to-alternate-styles-classes/145239>\
**Category:** Rails\
**Created:** [August 7, 2008, 2:41am UTC](https://www.ruby-forum.com/t/way-to-alternate-styles-classes/145239 "2008-08-07T02:41:06Z")\
**Posts on this page:** 2\
**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:** [August 7, 2008, 2:41am UTC](https://www.ruby-forum.com/t/way-to-alternate-styles-classes/145239/1 "2008-08-07T02:41:06Z")

</div>

Hi,

I’m trying to alternate between two classes to apply to a partial.

```
                                            <div

```

id=“ec\_line\_items”\>  
\<%=  
render :partial =\> ‘summary\_line\_item’, :collection =\>  
@ec\_order.ec\_line\_items %\>

Is it possible to apply a different background color depending on  
whether the row is even or odd? The content of the partial is  
below …

| Prescription #\<%= summary\_line\_item\_counter+1 %\> |
| 

| \<%= image\_tag '/images/RxICON\_Cream.gif', options = {:alt =\> ""} %\> | Refill Number | Drug Name | Day Supply |
| #\<%= summary\_line\_item.prescription\_number %\> | \<%= summary\_line\_item.description %\> | \<%= summary\_line\_item.day\_supply %\> |

 |

Thanks, - Dave

---

<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:** [August 7, 2008, 2:56am UTC](https://www.ruby-forum.com/t/way-to-alternate-styles-classes/145239/2 "2008-08-07T02:56:29Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Hi,
> 
> I’m trying to alternate between two classes to apply to a partial.

I believe there is a helper designed for this very thing called,  
“cycle.” It will cycle through an array of arguments given each time it  
is called.

So:

It also has some advanced featured, details in the API here:  
[http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M001738](http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M001738)
