Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numericality :within validator #144

Closed

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.

None yet

2 participants