I need to customize the font color of dynamic values based on the state_id. If incident.state_id = 1, the font should be red; if incident.state_id = 2, it should be yellow; and if incident.state_id = 3, it should be green.
incident.state_id = 1 : state.name = "Pending Investigation"
incident.state_id = 2 : state.name = "Investigation in Progress"
incident.state_id = 3 : state.name = "Investigation Closed"
Although I found a piece of CoffeeScript code, my knowledge in JavaScript/CoffeeScript is limited, so I'm not sure how to modify it for this task.
Currently, all state fields are displaying as red.
incidents.js.coffee:
$(".state").each ->
$this = $(this)
value = $this.text()
if value = 1
$this.addClass "red"
else if value = 2
$this.addClass "yellow"
else
$this.addClass "green"
application.html.erb
td.state {
}
.red {
color: #f99;
}
.yellow {
color: #ff9;
}
.green {
color: #9f9;
}
incidents.html.erb:
<td class="state"><%= incident.state.name %></td>