I’ve set validation in model:
validates_inclusion_of :height, :in => 36..96, :allow_nil => true, :message => 'must be between 3 and 8 feet'
Now I want to set the same validation ranges in JQ validation. I could repeat the same values in JavaScript file, but better way to do this would be getting validation range programmatically and output it through view.
How to get validation range programmatically in Rails, if possible at all?
You can access a model’s validations like so:
To get those particular values, something like:
Will return your range:
You can use
Range#minandRange#maxto get the integer values.To make it all convenient, make a couple methods like so: