Skip to content

Commit dcaf891

Browse files
author
Robert Mosolgo
authored
Merge pull request rmosolgo#3298 from connorshea/patch-1
Add example code for the `message` argument on validates.
2 parents 4c8beba + 5ab1fb7 commit dcaf891

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

guides/fields/validation.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,29 @@ All the validators below accept the following options:
4040
- `allow_nil: true` will permit `nil` (bypassing the validation)
4141
- `message: "..."` customizes the error message when the validation fails
4242

43+
For example:
44+
45+
```ruby
46+
field :comments, [Comment], null: true,
47+
description: "Find comments by author ID or author name" do
48+
argument :author_id, ID, required: false
49+
argument :author_name, String, required: false
50+
# Include a message for the end user if the validation fails:
51+
validates required: {
52+
one_of: [:author_id, :author_name],
53+
message: "May use either author_id or author_name, but not both."
54+
}
55+
end
56+
```
57+
4358
See each validator's API docs for details:
4459

4560
- `length: { maximum: ..., minimum: ..., is: ..., within: ... }` {{ "Schema::Validator::LengthValidator" | api_doc }}
4661
- `format: { with: /.../, without: /.../ }` {{ "Schema::Validator::FormatValidator" | api_doc }}
4762
- `numericality: { greater_than:, greater_than_or_equal_to:, less_than:, less_than_or_equal_to:, other_than:, odd:, even: }` {{ "Schema::Validator::NumericalityValidator" | api_doc }}
4863
- `inclusion: { in: [...] }` {{ "Schema::Validator::InclusionValidator" | api_doc }}
4964
- `exclusion: { in: [...] }` {{ "Schema::Validator::ExclusionValidator" | api_doc }}
50-
- `required: { one_of: [...] }` {{ "Schema::Validator::RequiredValidator" }}
65+
- `required: { one_of: [...] }` {{ "Schema::Validator::RequiredValidator" | api_doc }}
5166

5267

5368
Some of the validators accept customizable messages for certain validation failures; see the API docs for examples.

0 commit comments

Comments
 (0)