-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Parameter maximum value #1535
Comments
I'll label this as a feature request to support |
#1568 added a new feature to the ValuesValidator that allows a Proc to be supplied for anonymous custom validations. Using this, your example above might look like this. optional :per_page, values: { proc: ->(v) { v.positive? && v <= 100 } }, default: 10, type: Integer I should note that the ValuesValidator already accepted Ranges, so you also could have done this. optional :per_page, values: 1..100, default: 10, type: Integer For both your original example and my Range alternative, the validator will call A way to avoid this is (again) to use optional :per_page, values: { proc: ->(v) { (1..100).cover? v } }, default: 10, type: Integer |
Should we close this? |
When adding a parameter (i.e. per_page), is there a way to set the maximum value?
The cleanest (only) way I've found so far is to pass the entire array of possible options:
optional :per_page, values: [*1..100], default: 10, type: Integer
Is there a better way to achieve this?
The text was updated successfully, but these errors were encountered: