2016-02-28 3 views
0

Я хотел бы сделать условное форматирование в своих представлениях.Условное форматирование текста в Rails 4.2

Пожалуйста, найдите образец изображения для справки.

sample.jpg

Для «наличными» он работает хорошо, но я хочу сделать это для «денежные средства, полученные», «кредитная нота» и так далее ..

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> 
+0

Что там не там? Это красный цвет? – Sravan

+0

Да, сэр, .neg { цвет: # f00; } –

ответ

0

Hai Вы забрали данное условие только для cash, так что только он дает красный цвет, замените его на 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" || statement.description == "cash received" || statement.description == "credit note") ? "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>

Вот так.

+0

Вы пробовали это? – Sravan

+0

Спасибо за ответ, но я не хочу, чтобы все значения описания были красными. Я хочу, чтобы первое значение отображалось черным цветом, так как это счет. ожидая ответа .. –

+0

Сколько у вас значений, которые вам нужны в красном цвете? – Sravan

Смежные вопросы