From 4bbd05c90e5a62c0316307b3ca7c2262ed98b567 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Thu, 17 May 2012 10:54:29 -0500 Subject: fix validations docs --- .../lib/active_model/validations/numericality.rb | 36 +++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'activemodel/lib/active_model/validations/numericality.rb') diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb index 34d447a0fa..c73fa55ed3 100644 --- a/activemodel/lib/active_model/validations/numericality.rb +++ b/activemodel/lib/active_model/validations/numericality.rb @@ -1,5 +1,4 @@ module ActiveModel - # == Active Model Numericality Validator module Validations class NumericalityValidator < EachValidator @@ -93,22 +92,30 @@ module ActiveModel # validation contexts by default (+nil+), other options are :create # and :update. # * :only_integer - Specifies whether the value has to be an integer, e.g. an integral value (default is +false+). - # * :allow_nil - Skip validation if attribute is +nil+ (default is +false+). Notice that for fixnum and float columns empty strings are converted to +nil+. - # * :greater_than - Specifies the value must be greater than the supplied value. - # * :greater_than_or_equal_to - Specifies the value must be greater than or equal the supplied value. + # * :allow_nil - Skip validation if attribute is +nil+ (default is + # +false+). Notice that for fixnum and float columns empty strings are + # converted to +nil+. + # * :greater_than - Specifies the value must be greater than the + # supplied value. + # * :greater_than_or_equal_to - Specifies the value must be greater + # than or equal the supplied value. # * :equal_to - Specifies the value must be equal to the supplied value. - # * :less_than - Specifies the value must be less than the supplied value. - # * :less_than_or_equal_to - Specifies the value must be less than or equal the supplied value. + # * :less_than - Specifies the value must be less than the supplied + # value. + # * :less_than_or_equal_to - Specifies the value must be less than + # or equal the supplied value. # * :odd - Specifies the value must be an odd number. # * :even - Specifies the value must be an even number. - # * :if - Specifies a method, proc or string to call to determine if the validation should - # occur (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The - # method, proc or string should return or evaluate to a true or false value. - # * :unless - Specifies a method, proc or string to call to determine if the validation should - # not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The - # method, proc or string should return or evaluate to a true or false value. + # * :if - Specifies a method, proc or string to call to determine + # if the validation should occur (e.g. :if => :allow_validation, + # or :if => Proc.new { |user| user.signup_step > 2 }). The method, + # proc or string should return or evaluate to a true or false value. + # * :unless - Specifies a method, proc or string to call to determine + # if the validation should not occur (e.g. :unless => :skip_validation, + # or :unless => Proc.new { |user| user.signup_step <= 2 }). The method, + # proc or string should return or evaluate to a true or false value. # * :strict - Specifies whether validation should be strict. - # See ActiveModel::Validation#validates! for more information + # See ActiveModel::Validation#validates! for more information. # # The following checks can also be supplied with a proc or a symbol which corresponds to a method: # * :greater_than @@ -117,11 +124,12 @@ module ActiveModel # * :less_than # * :less_than_or_equal_to # + # For example: + # # class Person < ActiveRecord::Base # validates_numericality_of :width, :less_than => Proc.new { |person| person.height } # validates_numericality_of :width, :greater_than => :minimum_weight # end - # def validates_numericality_of(*attr_names) validates_with NumericalityValidator, _merge_attributes(attr_names) end -- cgit v1.2.3