我想在我的視圖中做一些條件格式。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; } –