title: Rails, is it possible to change the color depending on the value of an column of a table containing balance?
body: <p>index.html.erb</p>
  
  <pre><code>    &lt;% balance = 0 %&gt;
  
      &lt;table align="center" width="50%" cellpadding="1" cellspacing="5"&gt;  
          &lt;tr&gt;
              &lt;td&gt;Amount&lt;/td&gt;
              &lt;td&gt;Discount&lt;/td&gt;
              &lt;td&gt;Paid&lt;/td&gt;
              &lt;td&gt;Balance&lt;/td&gt;
          &lt;/tr&gt;   
  
  &lt;% @statements.each do |statement| %&gt;
  
    &lt;tr class="tr-&lt;%= cycle('odd', 'even') %&gt;"&gt;
  
      &lt;td class="col-1"&gt;&lt;%= statement.date %&gt;&lt;/td&gt;
      &lt;td class="col-3"&gt;&lt;%= statement.description %&gt;&lt;/td&gt;
  
      &lt;td class="col-1"&gt;&lt;%= number_with_precision(statement.amount, :delimiter =&gt; ",", :precision =&gt; 2) %&gt;&lt;/td&gt;
  
      &lt;td class="col-1 neg"&gt;&lt;%= number_with_precision(statement.discount, :delimiter =&gt; ",", :precision =&gt; 2) %&gt;&lt;/td&gt;
  
      &lt;td class="col-1 neg"&gt;&lt;%= number_with_precision(statement.paid, :delimiter =&gt; ",", :precision =&gt; 2) %&gt;&lt;/td&gt;
  
  
  &lt;% balance += statement.amount.to_f - statement.discount.to_f - statement.paid.to_f %&gt;
  
          &lt;% color = balance &gt;= 0 ? "pos" : "neg" %&gt;
  
          &lt;td class="col-1 &lt;%= color %&gt;"&gt;&lt;%= number_with_precision(balance.abs, :delimiter =&gt; ",", :precision =&gt; 2) %&gt;&lt;/td&gt;
  
  &lt;/tr&gt;
  
      &lt;% end %&gt;
  
    &lt;/table&gt;
  
  &lt;center&gt;&lt;p&gt;&lt;b&gt;&lt;%= number_to_currency(balance.abs, :unit =&gt; 'AED ', :delimiter =&gt; ",", :precision =&gt; 2) %&gt;&lt;/b&gt;&lt;/p&gt;&lt;/center&gt;
  </code></pre>
  
  <p>I would like to have change of colour of balance entity that is when balance is positive it must show black and when goes negative it must show in red.</p>
  
  <p>Here is my application.css.scss</p>
  
  <pre><code>.pos { color: #000; }
  .neg { color: #f00; }
  </code></pre>
  
  <p>I am not getting the result as expected.</p>
  
  <p>Please see the result as below;</p>
  
  <p><a href="http://i.stack.imgur.com/1KuvH.jpg" rel="nofollow">Sample data</a></p>
  
  <p><a href="http://i.stack.imgur.com/fVFrc.jpg" rel="nofollow">picture</a></p>