Skip to content

Commit

Permalink
Update readme with fail_fast option info
Browse files Browse the repository at this point in the history
  • Loading branch information
dgasper committed Sep 28, 2016
1 parent 8bfd1eb commit 32de18e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [#1486](https://github.com/ruby-grape/grape/pull/1486): Implemented except in values validator - [@jonmchan](https://github.com/jonmchan).
* [#1470](https://github.com/ruby-grape/grape/pull/1470): Drop support for ruby-2.0 - [@namusyaka](https://github.com/namusyaka).
* [#1490](https://github.com/ruby-grape/grape/pull/1490): Switch to Ruby-2.x+ syntax - [@namusyaka](https://github.com/namusyaka).
* [#1499](https://github.com/ruby-grape/grape/pull/1499): Support fail_fast param validation option - [@dgasper](https://github.com/dgasper).
* Your contribution here.

#### Fixes
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,23 @@ subject.rescue_from Grape::Exceptions::ValidationErrors do |e|
end
```

Grape returns all validation and coercion errors found by default. To skip all subsequent validation checks when a specific param is found invalid, use `fail_fast: true`.
For example:
```ruby
params do
required :beer, fail_fast: true
required :wine
end
```
will not check if `:wine` is present unless it finds `:beer`. The result of empty params would be a single `Grape::Exceptions::ValidationErrors` error.
Similarly
```ruby
params do
required :blah, allow_blank: false, regexp: /blah/, fail_fast: true
end
```
will not check if the `:blah` matches the regular expression if it is blank.

### I18n

Grape supports I18n for parameter-related error messages, but will fallback to English if
Expand Down

0 comments on commit 32de18e

Please sign in to comment.