<p>I am rendering a rails partial and I want to alternate the background color when it renders the partial.  I know that is not super clear so here is an example of what I want to do:</p>



Row One grey Background


Row Two yellow background


Row Three grey Background


Row Four yellow background



<ul>
<li>sorry stackoverflow seams to prevent the background colors from being shown but I think this makes my idea clear</li>
</ul>

<p>This is the view code that I am using  </p>

<pre><code>&lt;table&gt;
  &lt;%= render :partial =&gt; 'row' :collection =&gt; @rows %&gt;
&lt;/table&gt;
</code></pre>

<p>the _row.html.erb partial looks like this</p>

<pre><code>&lt;tr bgcolor="#AAAAAA"&gt;
  &lt;td&gt;&lt;%= row.name %&gt;&lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>The problem is I do not know how to change the background color for every other row.  Is there a way to do this?</p>

You could use the Cycle helper. Something like this:
```
```
<tr class="<%= cycle("even", "odd") %>">
  <td><%= row.name %></td>
</tr>
```
```
Or in your case use bgcolor instead, although i would recomend using css classes.
You can cycle through more than two values: cycle(‘first’, ‘second’, ‘third’, ‘and_more’).
There is also: reset_cycle(‘cycle_name’) This makes sure that on each iteration, you will start again with your first value of the cycle list.
Check the rails
documentation
for more examples.