Alternate row classes with Ruby on Rails
Using the built in TextHelper cycle method makes alternate row classes so easy in Ruby on Rails.
If your table rows are being ouput via a loop then you can use cycle() to automatically use alternate classes for each row...
<%- for item in @items do -%>
<tr class="<%= cycle("even", "odd") %>">
... use item ...
</tr>
<%- end -%>
Then in my CSS i'd use something like:
tr.even td{
background-color:#CCC;
}
tr.odd td{
background-color:#EEE;
}
About
Paul is a web developer for Kyanmedia web agency. He's lucky enough to write in Ruby on Rails full-time and uses this site to post snippets of code.
Contact
my name at gmail.com
More snippets
Take a look in the archive
Need a website?
Contact my employer. Make sure to check out our portfolio of work.
Hosting
I recommend hostingrails.com
1 comment made
This rocks, thank you!
Got something to say?