aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorAna María Martínez Gómez <ammartinez@suse.de>2018-08-07 17:35:13 +0200
committerAna María Martínez Gómez <ammartinez@suse.de>2018-08-07 17:35:13 +0200
commit3cb491f327de27d2d5106f4340e7b36c70cb9403 (patch)
treec8c8866b6dca2faec766ff63ca03133f5d9e53af /guides
parentb9807eb53880a386890aa1919cf812fb9876b805 (diff)
downloadrails-3cb491f327de27d2d5106f4340e7b36c70cb9403.tar.gz
rails-3cb491f327de27d2d5106f4340e7b36c70cb9403.tar.bz2
rails-3cb491f327de27d2d5106f4340e7b36c70cb9403.zip
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
Diffstat (limited to 'guides')
-rw-r--r--guides/source/active_record_validations.md7
1 files changed, 7 insertions, 0 deletions
diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md
index afe837a97c..3f13ef8d10 100644
--- a/guides/source/active_record_validations.md
+++ b/guides/source/active_record_validations.md
@@ -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