Way to alternate styles/classes?

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 %>                                                 </div>

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 ...

<div class="ec_line_item" style="width:100%"> <table cellpadding="0" cellspacing="0" border="0" width="100%">      <tr><td class="lineItemHeader" style="background-image:url('<%= image_path('/images/INSIDE_MENU_BAR-GreyRepeat_SM.gif'); %>');">Prescription #<span class="prescriptionNumber"><%= summary_line_item_counter+1 %></span></td></tr>      <tr><td style="background-color:#FFFFCC;">        <table cellpadding="3" cellspacing="0" border="0" width="100%">          <tr>            <td rowspan="2" valign="middle" align="center"><%= image_tag '/images/RxICON_Cream.gif', options = {:alt => ""} %></td>            <td align="center" class="summaryFieldHeader">Refill Number</td>            <td align="center" class="summaryFieldHeader">Drug Name</

           <td align="center" class="summaryFieldHeader">Day Supply</

         </tr>          <tr>            <td align="center" class="summaryField">#<%= summary_line_item.prescription_number %></td>            <td align="center" class="summaryField"><%= summary_line_item.description %></td>            <td align="center" class="summaryField"><%= summary_line_item.day_supply %></td>          </tr>        </table>      </td></tr> </table> </div>

Thanks, - Dave

laredotornado@zipmail.com 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:

<tr class=<%= cycle('odd', 'even') -%>

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