How to Change Font Color based on Conditional?


When a User checks off :good in the <strong>_form</strong>

<%= f.text_field :result_value %> <%= f.date_select :date_value %> <%= f.check_box :good %>

how can we render the font color in the index of that result (:result_value & :date_value) to green?

result.good below pulls up true or false in the index. I'll take that out once we represent true or false with colors: true = green, false = red (default color).

<% averaged.results.each do |result| %> <li> <%= result.result_value %> <%= result.date_value.strftime("%b %Y") %> <%= result.good %> </li> <% end %>


class Result < ActiveRecord::Base belongs_to :user belongs_to :quantified has_many :comments, as: :commentable default_scope { order('date_value DESC') } scope :good, -> { where(good: true) } scope :good_count, -> { good.count } end

Thank you so much for your help.


You could add a class to the LI based on the output?

<% if result.good == true %> <li class="green"> <% else %> <li> <% end %>

Then in your css just set a colour for that class?

.green { color: green; }


  • How to “average” two or more geography linestrings using C#/SQL Server 2008 spatial
  • Computing average for numpy array
  • Excel averageifs with or function
  • multiple options for a community connector configuration in Google Data Studio
  • calculate daily averages for 3d array
  • Get attributes of existing SVG elements and bind as data with d3.js
  • Setting color in a row of a Jtable
  • Can I use jquery to blank textarea fields or ajax like input boxes?
  • UIButton Borders Function Only Gives Back White Borders
  • Count query results on multi-join statements
  • How To Customize ASP.NET Chart Databound To SqlDataSource
  • How to modify the colors in the legend of a plot using a fill gradient?
  • Meteor helpers not available in Angular template
  • Highlight and Bold text in JTextPane
  • Xamarin Forms - UWP Fonts
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Spray.io: When (not) to use non-blocking route handling?
  • How reduce the height of an mschart by breaking up the y-axis
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • Modifying destination and filename of gulp-svg-sprite
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • GridView Sorting works once only
  • php design question - will a Helper help here?
  • Circular dependency while pushing http interceptor
  • Linker errors when using intrinsic function via function pointer
  • AngularJs get employee from factory
  • Proper way to use connect-multiparty with express.js?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Android Google Maps API OnLocationChanged only called once
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • sending mail using smtp is too slow
  • Django query for large number of relationships
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • Conditional In-Line CSS for IE and Others?