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") %>">