diff --git a/activemodel/lib/active_model/validations/acceptance.rb b/activemodel/lib/active_model/validations/acceptance.rb
index 18e71750de..8d5ebf527f 100644
--- a/activemodel/lib/active_model/validations/acceptance.rb
+++ b/activemodel/lib/active_model/validations/acceptance.rb
@@ -37,9 +37,6 @@ module ActiveModel
# Configuration options:
# * :message - A custom error message (default is: "must be
# accepted").
- # * :on - Specifies when this validation is active. Runs in all
- # validation contexts by default (+nil+), other options are :create
- # and :update.
# * :allow_nil - Skip validation if attribute is +nil+ (default
# is +true+).
# * :accept - Specifies value that is considered accepted.
@@ -47,19 +44,10 @@ module ActiveModel
# 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
- # 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 (for example,
- # 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.
+ #
+ # There is also a list of default options supported by every validator:
+ # +:if+, +:unless+, +:on+ and +:strict+.
+ # See ActiveModel::Validation#validates for more information
def validates_acceptance_of(*attr_names)
validates_with AcceptanceValidator, _merge_attributes(attr_names)
end
diff --git a/activemodel/lib/active_model/validations/confirmation.rb b/activemodel/lib/active_model/validations/confirmation.rb
index d41f401999..baa034eca6 100644
--- a/activemodel/lib/active_model/validations/confirmation.rb
+++ b/activemodel/lib/active_model/validations/confirmation.rb
@@ -46,22 +46,10 @@ module ActiveModel
# Configuration options:
# * :message - A custom error message (default is: "doesn't match
# confirmation").
- # * :on - Specifies when this validation is active. Runs in all
- # validation contexts by default (+nil+), other options are :create
- # and :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.
- # * :strict - Specifies whether validation should be strict.
- # See ActiveModel::Validation#validates! for more information.
+ #
+ # There is also a list of default options supported by every validator:
+ # +:if+, +:unless+, +:on+ and +:strict+.
+ # See ActiveModel::Validation#validates for more information
def validates_confirmation_of(*attr_names)
validates_with ConfirmationValidator, _merge_attributes(attr_names)
end
diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb
index a9a1af039c..3331162bc0 100644
--- a/activemodel/lib/active_model/validations/exclusion.rb
+++ b/activemodel/lib/active_model/validations/exclusion.rb
@@ -37,20 +37,10 @@ module ActiveModel
# attribute is +nil+ (default is +false+).
# * :allow_blank - If set to true, skips this validation if the
# attribute is blank(default is +false+).
- # * :on - Specifies when this validation is active. Runs in all
- # validation contexts by default (+nil+), other options are :create
- # and :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.
- # * :strict - Specifies whether validation should be strict.
- # See ActiveModel::Validation#validates! for more information.
+ #
+ # There is also a list of default options supported by every validator:
+ # +:if+, +:unless+, +:on+ and +:strict+.
+ # See ActiveModel::Validation#validates for more information
def validates_exclusion_of(*attr_names)
validates_with ExclusionValidator, _merge_attributes(attr_names)
end
diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb
index a2126f8372..80150229a0 100644
--- a/activemodel/lib/active_model/validations/format.rb
+++ b/activemodel/lib/active_model/validations/format.rb
@@ -101,23 +101,13 @@ module ActiveModel
# match will result in a successful validation. This can be provided as
# a proc or lambda returning regular expression which will be called at
# runtime.
- # * :on - Specifies when this validation is active. Runs in all
- # validation contexts by default (+nil+), other options are :create
- # and :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.
- # * :strict - Specifies whether validation should be strict.
- # See ActiveModel::Validation#validates! for more information.
# * :multiline - Set to true if your regular expression contains
# anchors that match the beginning or end of lines as opposed to the
# beginning or end of the string. These anchors are ^ and $.
+ #
+ # There is also a list of default options supported by every validator:
+ # +:if+, +:unless+, +:on+ and +:strict+.
+ # See ActiveModel::Validation#validates for more information
def validates_format_of(*attr_names)
validates_with FormatValidator, _merge_attributes(attr_names)
end
diff --git a/activemodel/lib/active_model/validations/inclusion.rb b/activemodel/lib/active_model/validations/inclusion.rb
index e7ad07f040..c995e28d64 100644
--- a/activemodel/lib/active_model/validations/inclusion.rb
+++ b/activemodel/lib/active_model/validations/inclusion.rb
@@ -36,20 +36,10 @@ module ActiveModel
# attribute is +nil+ (default is +false+).
# * :allow_blank - If set to +true+, skips this validation if the
# attribute is blank (default is +false+).
- # * :on - Specifies when this validation is active. Runs in all
- # validation contexts by default (+nil+), other options are :create
- # and :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.
- # * :strict - Specifies whether validation should be strict.
- # See ActiveModel::Validation#validates! for more information.
+ #
+ # There is also a list of default options supported by every validator:
+ # +:if+, +:unless+, +:on+ and +:strict+.
+ # See ActiveModel::Validation#validates for more information
def validates_inclusion_of(*attr_names)
validates_with InclusionValidator, _merge_attributes(attr_names)
end
diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb
index 3b0be96ac6..aa72ea41c7 100644
--- a/activemodel/lib/active_model/validations/length.rb
+++ b/activemodel/lib/active_model/validations/length.rb
@@ -96,24 +96,14 @@ module ActiveModel
# * :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. Runs in all
- # validation contexts by default (+nil+), other options are :create
- # and :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.
# * :tokenizer - Specifies how to split up the attribute string.
# (e.g. tokenizer: ->(str) { str.scan(/\w+/) } to count words
# as in above example). Defaults to ->(value) { value.split(//) }
# which counts individual characters.
- # * :strict - Specifies whether validation should be strict.
- # See ActiveModel::Validation#validates! for more information.
+ #
+ # There is also a list of default options supported by every validator:
+ # +:if+, +:unless+, +:on+ and +:strict+.
+ # See ActiveModel::Validation#validates for more information
def validates_length_of(*attr_names)
validates_with LengthValidator, _merge_attributes(attr_names)
end
diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb
index 6b3dd6caec..edebca94a8 100644
--- a/activemodel/lib/active_model/validations/numericality.rb
+++ b/activemodel/lib/active_model/validations/numericality.rb
@@ -90,9 +90,6 @@ module ActiveModel
#
# Configuration options:
# * :message - A custom error message (default is: "is not a number").
- # * :on - Specifies when this validation is active. Runs in all
- # 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
@@ -112,17 +109,10 @@ module ActiveModel
# 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.
- # * :strict - Specifies whether validation should be strict.
- # See ActiveModel::Validation#validates! for more information.
+ #
+ # There is also a list of default options supported by every validator:
+ # +:if+, +:unless+, +:on+ and +:strict+ .
+ # 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:
diff --git a/activemodel/lib/active_model/validations/presence.rb b/activemodel/lib/active_model/validations/presence.rb
index cb7e9104db..4592a1deb0 100644
--- a/activemodel/lib/active_model/validations/presence.rb
+++ b/activemodel/lib/active_model/validations/presence.rb
@@ -29,20 +29,10 @@ module ActiveModel
#
# Configuration options:
# * :message - A custom error message (default is: "can't be blank").
- # * :on - Specifies when this validation is active. Runs in all
- # validation contexts by default (+nil+), other options are :create
- # and :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.
- # * :strict - Specifies whether validation should be strict.
- # See ActiveModel::Validation#validates! for more information.
+ #
+ # There is also a list of default options supported by every validator:
+ # +:if+, +:unless+, +:on+ and +:strict+.
+ # See ActiveModel::Validation#validates for more information
def validates_presence_of(*attr_names)
validates_with PresenceValidator, _merge_attributes(attr_names)
end
diff --git a/activemodel/lib/active_model/validations/validates.rb b/activemodel/lib/active_model/validations/validates.rb
index 6c13d2b4a2..ecda9dffcf 100644
--- a/activemodel/lib/active_model/validations/validates.rb
+++ b/activemodel/lib/active_model/validations/validates.rb
@@ -69,14 +69,31 @@ module ActiveModel
# validator's initializer as +options[:in]+ while other types including
# regular expressions and strings are passed as +options[:with]+
#
+ # There is also a list of options that could be used along with validators:
+ # * :on - Specifies when this validation is active. Runs in all
+ # validation contexts by default (+nil+), other options are :create
+ # and :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.
+ # * :strict - Specifies whether validation should be strict.
+ # See ActiveModel::Validation#validates! for more information.
+ #
+ # Example:
+ #
+ # validates :password, :presence => true, :confirmation => true, :if => :password_required?
+ #
# Finally, the options +:if+, +:unless+, +:on+, +:allow_blank+, +:allow_nil+ and +:strict+
# can be given to one specific validator, as a hash:
#
# validates :password, :presence => { :if => :password_required? }, :confirmation => true
#
- # Or to all at the same time:
- #
- # validates :password, :presence => true, :confirmation => true, :if => :password_required?
#
def validates(*attributes)
defaults = attributes.extract_options!.dup