我有两种型号,一种带有卡片,另一种带有相关的奖励计划。我将它们全部显示在一个表中,在某些列中带有条件 if 语句,但我无法弄清楚为什么 if else 语句会搞砸我的列。我发布了两个示例,一个有效,一个无效。我需要第二个来添加一些额外的功能
这个例子有效
<table>
<tr>
<th>Card</th>
<th>General Rewards</th>
<th>Gas Amount</th>
<th>Movies Amount</th>
<th>Museums Amount</th>
<th>Theme Park Amount</th>
<th>Restaurant Amount</th>
<th>Department Store Amount</th>
</tr>
<% @cards.each do |card| %>
<tr>
<td><%= card.name %></td>
<td><%= card.general_rate %> </td>
<% card.rewards.each do |category| %>
<% if category.name.downcase == "gas" %>
<td><%= category.threshold_check(@gas) %></td>
<% end %>
<% if category.name.downcase == "movies" %>
<td><%= category.threshold_check(@movies) %></td>
<% end %>
<% if category.name.downcase == "museums" %>
<td><%= category.threshold_check(@museums) %></td>
<% end %>
<% if category.name.downcase == "theme parks" %>
<td><%= category.threshold_check(@theme_parks) %></td>
<% end %>
<% if category.name.downcase == "restaurants" %>
<td><%= category.threshold_check(@restaurants) %></td>
<% end %>
<% if category.name.downcase == "department stores" %>
<td><%= category.threshold_check(@department_stores) %></td>
<% end %>
<% end %>
</tr>
<% end %>
</table>
这会在末尾添加额外的列
<table>
<tr>
<th>Card</th>
<th>General Rewards</th>
<th>Gas Amount</th>
<th>Movies Amount</th>
<th>Museums Amount</th>
<th>Theme Park Amount</th>
<th>Restaurant Amount</th>
<th>Department Store Amount</th>
</tr>
<% @cards.each do |card| %>
<tr>
<td><%= card.name %></td>
<td><%= card.general_rate %> </td>
<% card.rewards.each do |category| %>
<td><%= category.name.downcase == "gas" ? category.threshold_check(@gas) : 0 %></td>
<td><%= category.name.downcase == "movies" ? category.threshold_check(@movies) : 0 %></td>
<td><%= category.name.downcase == "museums" ? category.threshold_check(@museums) : 0 %></td>
<td><%= category.name.downcase == "theme parks" ? category.threshold_check(@theme_parks) : 0 %></td>
<td><%= category.name.downcase == "restaurants" ? category.threshold_check(@restaurants) : 0 %></td>
<td><%= category.name.downcase == "department stores" ? category.threshold_check(@department_stores) : 0 %></td>
<% end %>
</tr>
<% end %>
</table>