I am trying to write a rails application the involves geographic lat and long values and I’ve written a validation for this below:
validates :latitude, numericality: {greater_than_or_equal_to: -89.9999, less_than_or_equal_to: 89.9999}, allow_nil: true
Note: latitude and longitude are decimal values with precision: 6 scale: 4 and precision 7 scale: 4 respectively. (Latitude goes from -90 to 90 (exclusive) and longitude goes from -180 to 180 (inclusive))
However, this code is passing -90 and 90 respectively when it should in fact fail. Does numericality validation take more than 1 arguments as used above? How would I write this validation properly?
Thank you.
EDIT: I have taken a look at the documentation for the validator and it only checks for:
{ :greater_than => :>, :greater_than_or_equal_to => :>=, :equal_to => :==, :less_than => :<, :less_than_or_equal_to => :<=, :odd => :odd?, :even => :even? }
So I assumed that the way I used it above would work.
I’m not able to reproduce this problem: