grape
grape copied to clipboard
set custom message when using proc to validate value
How can I use a proc to validate and use a custom message?
This way is deprecated:
params do
requires :e, values: { proc: -> (v) { v.even? }, message: 'must be even' }
end
The new way doesn't support a custom message:
params do
requires :e, values: -> (v) { v.even? }
end
I don't believe it's possible. Would be a good feature to add.
@dblock , what do you think about enhancing the values[:value]
to allow proc with arity 1 to support this use case?
params do
requires :e, values: { value: -> (v) { v.even? }, message: 'must be even' }
end
I like it. Give the code a try?
sure, I'll give it a go.
Turns out my PR description didn't close this automatically after the merge, @dblock could you close this for us?