From 29e053979e719937a1f5d235ac6cd83a530d020c Mon Sep 17 00:00:00 2001 From: CassioMarques Date: Tue, 11 Nov 2008 22:36:37 -0200 Subject: Changed conditional validation with Proc to use :unless instead of :if --- railties/doc/guides/source/activerecord_validations_callbacks.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/doc/guides/source') diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt index 23978c0cb8..29be2182ce 100644 --- a/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -358,14 +358,14 @@ class Person < ActiveRecord::Base end ------------------------------------------------------------------ -=== Using a Proc object with the +:if+ option +=== Using a Proc object with the +:if+ and :+unless+ options Finally, it's possible to associate +:if+ and +:unless+ with a Ruby Proc object which will be called. Using a Proc object can give you the hability to write a condition that will be executed only when the validation happens and not when your code is loaded by the Ruby interpreter. This option is best suited when writing short validation methods, usually one-liners. [source, ruby] ------------------------------------------------------------------ class Account < ActiveRecord::Base - validates_confirmation_of :password, :if => Proc.new { |a| !a.password.blank? } + validates_confirmation_of :password, :unless => Proc.new { |a| a.password.blank? } end ------------------------------------------------------------------ -- cgit v1.2.3