1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add lambdas in conditional validations

As `Lambdas` are a type of `Proc`, they can also be used in the
`if`/`unless` option of a validation to decide when the validation is
executed. Add this case to the guide for clarification.

Closes https://github.com/rails/rails/issues/33212
This commit is contained in:
Ana María Martínez Gómez 2018-08-07 17:35:13 +02:00
parent b9807eb538
commit 3cb491f327

View file

@ -927,6 +927,13 @@ class Account < ApplicationRecord
end
```
As `Lambdas` are a type of `Proc`, they can also be used to write inline
conditions in a shorter way.
```ruby
validates :password, confirmation: true, unless: -> { password.blank? }
```
### Grouping Conditional validations
Sometimes it is useful to have multiple validations use one condition. It can