From 64092de25727c1943807bf5345107d90428135a0 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 2 May 2008 14:45:23 +0100 Subject: Improve documentation coverage and markup Signed-off-by: Pratik Naik --- activemodel/lib/active_model/validations.rb | 20 +++++----- .../lib/active_model/validations/acceptance.rb | 26 ++++++------- .../lib/active_model/validations/associated.rb | 14 +++---- .../lib/active_model/validations/confirmation.rb | 16 ++++---- .../lib/active_model/validations/exclusion.rb | 16 ++++---- activemodel/lib/active_model/validations/format.rb | 20 +++++----- .../lib/active_model/validations/inclusion.rb | 16 ++++---- activemodel/lib/active_model/validations/length.rb | 43 +++++++++++----------- .../lib/active_model/validations/numericality.rb | 32 ++++++++-------- .../lib/active_model/validations/presence.rb | 26 +++++++------ .../lib/active_model/validations/uniqueness.rb | 18 ++++----- 11 files changed, 125 insertions(+), 122 deletions(-) (limited to 'activemodel/lib/active_model') diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index b15bdb06ca..34ef3b8f6e 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -10,7 +10,7 @@ module ActiveModel DEFAULT_VALIDATION_OPTIONS = { :on => :save, :allow_nil => false, :allow_blank => false, :message => nil }.freeze # Adds a validation method or block to the class. This is useful when - # overriding the #validate instance method becomes too unwieldly and + # overriding the +validate+ instance method becomes too unwieldly and # you're looking for more descriptive declaration of your validations. # # This can be done with a symbol pointing to a method: @@ -35,8 +35,8 @@ module ActiveModel # end # end # - # This usage applies to #validate_on_create and #validate_on_update as well. - + # This usage applies to +validate_on_create+ and +validate_on_update as well+. + # # Validates each attribute against a block. # # class Person < ActiveRecord::Base @@ -46,14 +46,14 @@ module ActiveModel # end # # Options: - # * on - Specifies when this validation is active (default is :save, other options :create, :update) - # * allow_nil - Skip validation if attribute is nil. - # * allow_blank - Skip validation if attribute is blank. - # * 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 + # * :on - Specifies when this validation is active (default is :save, other options :create, :update) + # * :allow_nil - Skip validation if attribute is +nil+. + # * :allow_blank - Skip validation if attribute is blank. + # * :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 + # * :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. def validates_each(*attrs) options = attrs.extract_options!.symbolize_keys diff --git a/activemodel/lib/active_model/validations/acceptance.rb b/activemodel/lib/active_model/validations/acceptance.rb index 7363717858..9be7d51ffb 100644 --- a/activemodel/lib/active_model/validations/acceptance.rb +++ b/activemodel/lib/active_model/validations/acceptance.rb @@ -8,22 +8,22 @@ module ActiveModel # validates_acceptance_of :eula, :message => "must be abided" # end # - # If the database column does not exist, the terms_of_service attribute is entirely virtual. This check is - # performed only if terms_of_service is not nil and by default on save. + # If the database column does not exist, the :terms_of_service attribute is entirely virtual. This check is + # performed only if :terms_of_service is not +nil+ and by default on save. # # Configuration options: - # * message - A custom error message (default is: "must be accepted") - # * on - Specifies when this validation is active (default is :save, other options :create, :update) - # * allow_nil - Skip validation if attribute is nil. (default is true) - # * accept - Specifies value that is considered accepted. The default value is a string "1", which - # makes it easy to relate to an HTML checkbox. This should be set to 'true' if you are validating a database - # column, since the attribute is typecast from "1" to true before validation. - # * 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 + # * :message - A custom error message (default is: "must be accepted") + # * :on - Specifies when this validation is active (default is :save, other options :create, :update) + # * :allow_nil - Skip validation if attribute is +nil+. (default is +true+) + # * :accept - Specifies value that is considered accepted. The default value is a string "1", which + # makes it easy to relate to an HTML checkbox. This should be set to +true+ if you are validating a database + # column, since the attribute is typecasted from "1" to +true+ before validation. + # * :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. - # * 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. def validates_acceptance_of(*attr_names) configuration = { :message => ActiveRecord::Errors.default_error_messages[:accepted], :on => :save, :allow_nil => true, :accept => "1" } configuration.update(attr_names.extract_options!) diff --git a/activemodel/lib/active_model/validations/associated.rb b/activemodel/lib/active_model/validations/associated.rb index dbb098628b..ae3e4974bc 100644 --- a/activemodel/lib/active_model/validations/associated.rb +++ b/activemodel/lib/active_model/validations/associated.rb @@ -21,16 +21,16 @@ module ActiveModel # ...this would specify a circular dependency and cause infinite recursion. # # NOTE: This validation will not fail if the association hasn't been assigned. If you want to ensure that the association - # is both present and guaranteed to be valid, you also need to use validates_presence_of. + # is both present and guaranteed to be valid, you also need to use +validates_presence_of+. # # Configuration options: - # * message - A custom error message (default is: "is invalid") - # * on Specifies when this validation is active (default is :save, other options :create, :update) - # * 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 + # * :message - A custom error message (default is: "is invalid") + # * :on Specifies when this validation is active (default is :save, other options :create, :update) + # * :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 + # * :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. def validates_associated(*attr_names) configuration = { :message => ActiveRecord::Errors.default_error_messages[:invalid], :on => :save } diff --git a/activemodel/lib/active_model/validations/confirmation.rb b/activemodel/lib/active_model/validations/confirmation.rb index 79c6635177..ba4a18adb7 100644 --- a/activemodel/lib/active_model/validations/confirmation.rb +++ b/activemodel/lib/active_model/validations/confirmation.rb @@ -15,20 +15,20 @@ module ActiveModel # # The added +password_confirmation+ attribute is virtual; it exists only as an in-memory attribute for validating the password. # To achieve this, the validation adds accessors to the model for the confirmation attribute. NOTE: This check is performed - # only if +password_confirmation+ is not nil, and by default only on save. To require confirmation, make sure to add a presence + # only if +password_confirmation+ is not +nil+, and by default only on save. To require confirmation, make sure to add a presence # check for the confirmation attribute: # # validates_presence_of :password_confirmation, :if => :password_changed? # # Configuration options: - # * message - A custom error message (default is: "doesn't match confirmation") - # * on - Specifies when this validation is active (default is :save, other options :create, :update) - # * 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 + # * :message - A custom error message (default is: "doesn't match confirmation") + # * :on - Specifies when this validation is active (default is :save, other options :create, :update) + # * :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. - # * 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. def validates_confirmation_of(*attr_names) configuration = { :message => ActiveRecord::Errors.default_error_messages[:confirmation], :on => :save } configuration.update(attr_names.extract_options!) diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb index a17c517baa..f3367abcf8 100644 --- a/activemodel/lib/active_model/validations/exclusion.rb +++ b/activemodel/lib/active_model/validations/exclusion.rb @@ -10,15 +10,15 @@ module ActiveModel # end # # Configuration options: - # * in - An enumerable object of items that the value shouldn't be part of - # * message - Specifies a custom error message (default is: "is reserved") - # * allow_nil - If set to true, skips this validation if the attribute is null (default is: false) - # * allow_blank - If set to true, skips this validation if the attribute is blank (default is: false) - # * 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 + # * :in - An enumerable object of items that the value shouldn't be part of + # * :message - Specifies a custom error message (default is: "is reserved") + # * :allow_nil - If set to +true+, skips this validation if the attribute is +nil+ (default is: +false+) + # * :allow_blank - If set to +true+, skips this validation if the attribute is blank (default is: +false+) + # * :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 + # * :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. def validates_exclusion_of(*attr_names) configuration = { :message => ActiveRecord::Errors.default_error_messages[:exclusion], :on => :save } diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb index f8395543ec..1320ef646a 100644 --- a/activemodel/lib/active_model/validations/format.rb +++ b/activemodel/lib/active_model/validations/format.rb @@ -8,21 +8,21 @@ module ActiveModel # validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create # end # - # Note: use \A and \Z to match the start and end of the string, ^ and $ match the start/end of a line. + # Note: use \A and \Z to match the start and end of the string, ^ and $ match the start/end of a line. # # A regular expression must be provided or else an exception will be raised. # # Configuration options: - # * message - A custom error message (default is: "is invalid") - # * allow_nil - If set to true, skips this validation if the attribute is null (default is: false) - # * allow_blank - If set to true, skips this validation if the attribute is blank (default is: false) - # * with - The regular expression used to validate the format with (note: must be supplied!) - # * on Specifies when this validation is active (default is :save, other options :create, :update) - # * 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 + # * :message - A custom error message (default is: "is invalid") + # * :allow_nil - If set to +true+, skips this validation if the attribute is +nil+ (default is: +false+) + # * :allow_blank - If set to +true+, skips this validation if the attribute is blank (default is: +false+) + # * :with - The regular expression used to validate the format with (note: must be supplied!) + # * :on - Specifies when this validation is active (default is :save, other options :create, :update) + # * :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 + # * :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. def validates_format_of(*attr_names) configuration = { :message => ActiveRecord::Errors.default_error_messages[:invalid], :on => :save, :with => nil } diff --git a/activemodel/lib/active_model/validations/inclusion.rb b/activemodel/lib/active_model/validations/inclusion.rb index 2cfa1d6107..9fc1caaabe 100644 --- a/activemodel/lib/active_model/validations/inclusion.rb +++ b/activemodel/lib/active_model/validations/inclusion.rb @@ -10,15 +10,15 @@ module ActiveModel # end # # Configuration options: - # * in - An enumerable object of available items - # * message - Specifies a custom error message (default is: "is not included in the list") - # * allow_nil - If set to true, skips this validation if the attribute is null (default is: false) - # * allow_blank - If set to true, skips this validation if the attribute is blank (default is: false) - # * 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 + # * :in - An enumerable object of available items + # * :message - Specifies a custom error message (default is: "is not included in the list") + # * :allow_nil - If set to +true+, skips this validation if the attribute is null (default is: +false+) + # * :allow_blank - If set to +true+, skips this validation if the attribute is blank (default is: +false+) + # * :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 + # * :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. def validates_inclusion_of(*attr_names) configuration = { :message => ActiveRecord::Errors.default_error_messages[:inclusion], :on => :save } diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 5e5e0ad4e6..673ad33974 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -6,35 +6,34 @@ module ActiveModel # Validates that the specified attribute matches the length restrictions supplied. Only one option can be used at a time: # # class Person < ActiveRecord::Base - # validates_length_of :first_name, :maximum=>30 - # validates_length_of :last_name, :maximum=>30, :message=>"less than %d if you don't mind" + # validates_length_of :first_name, :maximum => 30 + # validates_length_of :last_name, :maximum => 30, :message => "less than %d if you don't mind" # validates_length_of :fax, :in => 7..32, :allow_nil => true # validates_length_of :phone, :in => 7..32, :allow_blank => true # validates_length_of :user_name, :within => 6..20, :too_long => "pick a shorter name", :too_short => "pick a longer name" - # validates_length_of :fav_bra_size, :minimum=>1, :too_short=>"please enter at least %d character" - # validates_length_of :smurf_leader, :is=>4, :message=>"papa is spelled with %d characters... don't play me." + # validates_length_of :fav_bra_size, :minimum => 1, :too_short => "please enter at least %d character" + # validates_length_of :smurf_leader, :is => 4, :message => "papa is spelled with %d characters... don't play me." # end # # Configuration options: - # * minimum - The minimum size of the attribute - # * maximum - The maximum size of the attribute - # * is - The exact size of the attribute - # * within - A range specifying the minimum and maximum size of the attribute - # * in - A synonym(or alias) for :within - # * allow_nil - Attribute may be nil; skip validation. - # * allow_blank - Attribute may be blank; skip validation. - # - # * too_long - The error message if the attribute goes over the maximum (default is: "is too long (maximum is %d characters)") - # * too_short - The error message if the attribute goes under the minimum (default is: "is too short (min is %d characters)") - # * wrong_length - The error message if using the :is method and the attribute is the wrong size (default is: "is the wrong length (should be %d characters)") - # * message - The error message to use for a :minimum, :maximum, or :is violation. An alias of the appropriate too_long/too_short/wrong_length message - # * on - Specifies when this validation is active (default is :save, other options :create, :update) - # * 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 + # * :minimum - The minimum size of the attribute + # * :maximum - The maximum size of the attribute + # * :is - The exact size of the attribute + # * :within - A range specifying the minimum and maximum size of the attribute + # * :in - A synonym (or alias) for :within + # * :allow_nil - Attribute may be +nil+; skip validation. + # * :allow_blank - Attribute may be blank; skip validation. + # * :too_long - The error message if the attribute goes over the maximum (default is: "is too long (maximum is %d characters)") + # * :too_short - The error message if the attribute goes under the minimum (default is: "is too short (min is %d characters)") + # * :wrong_length - The error message if using the :is method and the attribute is the wrong size (default is: "is the wrong length (should be %d characters)") + # * :message - The error message to use for a :minimum, :maximum, or :is violation. An alias of the appropriate :too_long/too_short/wrong_length message + # * :on - Specifies when this validation is active (default is :save, other options :create, :update) + # * :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. - # * 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. def validates_length_of(*attrs) # Merge given options with defaults. options = { diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb index 4c4e0ce952..8f5c5e8df8 100644 --- a/activemodel/lib/active_model/validations/numericality.rb +++ b/activemodel/lib/active_model/validations/numericality.rb @@ -8,29 +8,29 @@ module ActiveModel # Validates whether the value of the specified attribute is numeric by trying to convert it to # a float with Kernel.Float (if integer is false) or applying it to the regular expression - # /\A[\+\-]?\d+\Z/ (if integer is set to true). + # /\A[\+\-]?\d+\Z/ (if integer is true). # # class Person < ActiveRecord::Base # validates_numericality_of :value, :on => :create # end # # Configuration options: - # * message - A custom error message (default is: "is not a number") - # * on Specifies when this validation is active (default is :save, other options :create, :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 - # * 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 - # * 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 + # * :message - A custom error message (default is: "is not a number") + # * :on Specifies when this validation is active (default is :save, other options :create, :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 + # * :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 + # * :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 + # * :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. def validates_numericality_of(*attr_names) configuration = { :on => :save, :only_integer => false, :allow_nil => false } diff --git a/activemodel/lib/active_model/validations/presence.rb b/activemodel/lib/active_model/validations/presence.rb index 3dd2c97cd8..62e466901b 100644 --- a/activemodel/lib/active_model/validations/presence.rb +++ b/activemodel/lib/active_model/validations/presence.rb @@ -7,22 +7,26 @@ module ActiveModel # validates_presence_of :first_name # end # - # The first_name attribute must be in the object and it cannot be blank. + # The +first_name+ attribute must be in the object and it cannot be blank. # - # If you want to validate the presence of a boolean field (where the real values are true and false), - # you will want to use validates_inclusion_of :field_name, :in => [true, false] - # This is due to the way Object#blank? handles boolean values. false.blank? # => true + # If you want to validate the presence of a boolean field (where the real values are +true+ and +false+), + # you will want to use + # + # validates_inclusion_of :field_name, :in => [true, false] + # + # This is due to the way Object#blank? handles boolean values: + # + # false.blank? # => true # # Configuration options: - # * message - A custom error message (default is: "can't be blank") - # * on - Specifies when this validation is active (default is :save, other options :create, :update) - # * 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 + # * :message - A custom error message (default is: "can't be blank") + # * :on - Specifies when this validation is active (default is :save, other options :create, :update) + # * :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 + # * :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. - # def validates_presence_of(*attr_names) configuration = { :message => ActiveRecord::Errors.default_error_messages[:blank], :on => :save } configuration.update(attr_names.extract_options!) diff --git a/activemodel/lib/active_model/validations/uniqueness.rb b/activemodel/lib/active_model/validations/uniqueness.rb index 37a84dc06d..2b47c6bc09 100644 --- a/activemodel/lib/active_model/validations/uniqueness.rb +++ b/activemodel/lib/active_model/validations/uniqueness.rb @@ -23,16 +23,16 @@ module ActiveModel # unique index on the field. See +add_index+ for more information. # # Configuration options: - # * message - Specifies a custom error message (default is: "has already been taken") - # * scope - One or more columns by which to limit the scope of the uniqueness constraint. - # * case_sensitive - Looks for an exact match. Ignored by non-text columns (false by default). - # * allow_nil - If set to true, skips this validation if the attribute is null (default is: false) - # * allow_blank - If set to true, skips this validation if the attribute is blank (default is: false) - # * 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 + # * :message - Specifies a custom error message (default is: "has already been taken") + # * :scope - One or more columns by which to limit the scope of the uniqueness constraint. + # * :case_sensitive - Looks for an exact match. Ignored by non-text columns (+false+ by default). + # * :allow_nil - If set to +true+, skips this validation if the attribute is +nil+ (default is: +false+) + # * :allow_blank - If set to +true+, skips this validation if the attribute is blank (default is: +false+) + # * :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 + # * :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. def validates_uniqueness_of(*attr_names) configuration = { :message => ActiveRecord::Errors.default_error_messages[:taken] } -- cgit v1.2.3