I am working on a Rails 3 application and need to display some test results in the following format:
TestLower TestResult TestUpper
1.1 1.5 2.0
What I would like to do, is give the result one css class if the value is within the Lower and Upper limit and then give it a different css class if the value falls outside of the range.
I have used if and unless statements before but this is a little more complicated because I need to compare one value against two others, rather than one value against one other.
The only way I can think of doing it would involve quite a few if statements and fallbacks. Such as ‘if @lab.TestResult > @lab.TestLower’ and then have another one the same that checks it’s lower than the TestUpper.
Is there a simple way of doing this? Maybe a rails number helper of some form?
Any help would be appreciated!
Ruby also has
between?:You could use this in combination with the
content_taghelper in rails: