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/html/activerecord_validations_callbacks.html | 6 +++--- railties/doc/guides/source/activerecord_validations_callbacks.txt | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/doc') diff --git a/railties/doc/guides/html/activerecord_validations_callbacks.html b/railties/doc/guides/html/activerecord_validations_callbacks.html index a81c6c0c64..209722e9e0 100644 --- a/railties/doc/guides/html/activerecord_validations_callbacks.html +++ b/railties/doc/guides/html/activerecord_validations_callbacks.html @@ -259,7 +259,7 @@ ul#navMain {
  • Using a string with the :if and :unless options
  • -
  • Using a Proc object with the :if option
  • +
  • Using a Proc object with the :if and :unless options
  • @@ -690,7 +690,7 @@ http://www.gnu.org/software/src-highlite --> validates_presence_of :surname, :if => "name.nil?" end -

    5.3. Using a Proc object with the :if option

    +

    5.3. 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.

    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
     
    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