I am trying to validate a float that can be between 1 and 6.5 but only increments of .5 so {1, 1.5, 2.0, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5}. Is there any way to validate this in rails. So far I have:
validates :value, :inclusion => 1..6.5, is_value_valid => true
def is_value_valid
if self.value % 0.5 == 0
true
else
false
end
end
I am getting errors when I am testing, I do not think this is how you call the is_value_valid method.
You can validate it with a custom method, so your complete validation should look like this: