Yet another alternating row implementation
In my application_helper.rb, I added the following:
1 2 def even_odd(tag_name, options = {}, open = true) 3 @even_odd_counters = Hash.new(false) unless defined?(@even_odd_counters) 4 @even_odd_counters[tag_name] = !@even_odd_counters[tag_name] 5 ((options['class'] ||= '') << ' odd').strip! if @even_odd_counters[tag_name] 6 tag(tag_name, options, open) 7 end 8 9 def even_odd_reset(tag_name) 10 @even_odd_counters = Hash.new(false) unless defined?(@even_odd_counters) 11 @even_odd_counters[tag_name] = false 12 end
This implementation uses the tag() method in Rails, so you simply pass it the same arguments. One difference, however, is that the "open" parameter is true by default, as the majority of the time this will be used for TR's (and I use it for DT and DD sometimes).
I have included a simple "reset" method as well. I realize I'm duplicating the first line in both methods, but this was a quick-and-dirty addition.