Skip to content

Conversation

kristianmandrup
Copy link

I am trying to simplify the numericality validator a little by allowing something like

validates :price_range, :numericality => {:within => 10..20}

instead of

validates :price_range, :numericality => {:greater_than_or_equal_to => 10, :less_than_or_equal_to => 20}

It looks to me like the :within option currently only works for the length of an attribute?

I tried to add a test case and an update to the translation file, but I don't know enough about the Rails internals for validations and how it works behind the scenes.

@josevalim
Copy link
Contributor

You don't need to add a new translation option. You just need to break :within into two options. For example: :within => 10..20 should become :less_than_or_equal_to => 20 and :greater_than_or_equal_to => 10. I believe this is how the length validator behaves.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants