如何为div变量创建动态类?

时间:2023-01-22 20:34:41

I have the following code in an ERB file:

我在ERB文件中有以下代码:

<table border="1">
    <% @lists.each do |list| %>
        <tr class="even">
            <td><%= link_to list.title, list %></td>
            <td><%= link_to 'Edit', edit_list_path(list) %></td>
            <td><%= button_to "Destroy", list_path(list), :method => :delete %></td>
        </tr>
    <% end %>
</table>

I want to make the <tr class="even" line dynamic. Each tr should get the class either "even" or "odd" depending on a counter variable that gets incremented every time my loop starts over. However, I cannot figure out the best way to implement this.

我想让

1 个解决方案

#1


3  

Use this nice helper :)

使用这个好帮手:)

<tr class="<%= cycle("even", "odd") %>">

#1


3  

Use this nice helper :)

使用这个好帮手:)

<tr class="<%= cycle("even", "odd") %>">