More Zebras
Update: OK, you got me. You should really use the built-in Rails helper, cycle.
<table class="Grid">
<% for user in @users %>
<tr class="<%= cycle('Even', 'Odd') %>">
<td>
... Stuff Here
</td>
</tr>
<% end %>
</table>
def zebra_stripe( index, even_class="Even", odd_class="Odd" ) index % 2 == 0 ? even_class : odd_class endIn the view, you use the rubyesque
.each_with_index like this:
<table class="Grid">
<% @users.each_with_index do |user, i| %>
<tr class="<%= zebra_stripe(i) %>">
<td>
... Stuff Here
</td>
</tr>
<% end %>
</table>
Simple as that!