Way to alternate styles/classes?


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

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

<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('<%=
%>');">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%">
           <td rowspan="2" valign="middle" align="center"><%=
image_tag '/images/RxICON_Cream.gif', options = {:alt => ""} %></td>
           <td align="center" class="summaryFieldHeader">Refill
           <td align="center" class="summaryFieldHeader">Drug Name</

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

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

Thanks, - Dave

laredotornado@zipmail.com wrote:


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.


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

It also has some advanced featured, details in the API here: