From 3cb491f327de27d2d5106f4340e7b36c70cb9403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Tue, 7 Aug 2018 17:35:13 +0200 Subject: 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 --- guides/source/active_record_validations.md | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'guides/source/active_record_validations.md') 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 -- cgit v1.2.3