views:

33

answers:

2

Desired Output:

<ul>
 <li class="odd">stuff</li>
 <li class="even">stuff</li>
 <li class="odd">stuff</li>
 <li class="even">stuff</li>
 <li class="odd">stuff</li>
 <li class="even">stuff</li>
 <li class="odd">stuff</li>
 <li class="even">stuff</li>
</ul>

CSS:

.odd {color:blue}
.even{color:red;}

In rails 3 is there a clean way to do this without counters etc?

thanks

+1  A: 

Strictly speaking not really rails but a clean way achieving odd/even is with jquery on the client side: http://api.jquery.com/odd-selector/

leonm
+1  A: 

The Rails Way to do this is to use cycle.

<li class="<%= cycle('even', 'odd') -%>">stuff</li>

Documentation

Raphomet