diff options
Diffstat (limited to 'railties/guides/source/active_record_validations_callbacks.textile')
-rw-r--r-- | railties/guides/source/active_record_validations_callbacks.textile | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 72ac8d2db9..349d02c1f6 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -517,6 +517,18 @@ class Person < ActiveRecord::Base end </ruby> +h3. Strict Validations + +You can also specify validations to be strict and raise +ActiveModel::StrictValidationFailed+ when the object is invalid. + +<ruby> +class Person < ActiveRecord::Base + validates :name, :presence => { :strict => true } +end + +Person.new.valid? => ActiveModel::StrictValidationFailed: Name can't be blank +</ruby> + h3. Conditional Validation Sometimes it will make sense to validate an object just when a given predicate is satisfied. You can do that by using the +:if+ and +:unless+ options, which can take a symbol, a string or a +Proc+. You may use the +:if+ option when you want to specify when the validation *should* happen. If you want to specify when the validation *should not* happen, then you may use the +:unless+ option. |