我想在我的视图中做一些条件格式。Rails 4.2中的条件文本颜色格式
请查找示例图片以供参考。
对于“现金”这是工作正常,但我想这样做的“收到的现金”,“信用票据”等..
index.html.erb
<div class="container-fluid">
<% balance = 0 %>
<div class="table-responsive myTable">
<table class="table listing text-center">
<tr class="tr-head">
<td>Date</td>
<td>Description</td>
<td>Amount</td>
<td>Discount</td>
<td>Paid</td>
<td>Balance</td>
</tr>
<tr>
<td></td>
</tr>
<% @statements.each do |statement| %>
<tr class="tr-<%= cycle('odd', 'even') %>">
<td class="col-1"><%= statement.date %></td>
<% color = (statement.description == "cash") ? "neg" : "pos" %>
<td class="col-3 <%= color %>"><%= statement.description %></td>
<td class="col-1"><%= number_with_precision(statement.amount, :delimiter => ",", :precision => 2) %></td>
<td class="col-1 neg"><%= number_with_precision(statement.discount, :delimiter => ",", :precision => 2) %></td>
<td class="col-1 neg"><%= number_with_precision(statement.paid, :delimiter => ",", :precision => 2) %></td>
<% balance += statement.amount.to_f - statement.discount.to_f - statement.paid.to_f %>
<% color = balance >= 0 ? "pos" : "neg" %>
<td class="col-1 <%= color %>"><%= number_with_precision(balance.abs, :delimiter => ",", :precision => 2) %></td>
</tr>
<% end %>
</table>
</div>
</div>
什么是否定的?它是红色的吗? – Sravan
是的,先生.neg {0}颜色:#f00; } –