开发者

Rails cycle helper with a few exceptions

开发者 https://www.devze.com 2023-02-14 12:35 出处:网络
I\'m using the Rails cycle() helper method in the standa开发者_Go百科rd way with table rows to make alternating rows different background colors. However, I want an occasional row or two (that match c

I'm using the Rails cycle() helper method in the standa开发者_Go百科rd way with table rows to make alternating rows different background colors. However, I want an occasional row or two (that match certain criteria) to be a different, third color, without interrupting the cycle.

In other words, I want rows like:

white
black
red
black
white
black
white

Instead of:

white
black
red
white
black
white

What's the best way to do this?


Got to store it in a temporary variable and make the call to cycle() to ensure it is up-to-date.

<%
class = cycle('white', 'black', :name => 'colors')
class = 'red' if should_be_highlighted
%>
<tr class="<%= class %>">

You could wrap this up nicely in your own helper.

0

精彩评论

暂无评论...
验证码 换一张
取 消