diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/validations.rb | 16 | ||||
-rw-r--r-- | activerecord/lib/active_record/validations/associated.rb | 2 |
2 files changed, 16 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 26c1a9db93..c192e02660 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -1,5 +1,5 @@ module ActiveRecord - # = Active Record Validations + # = Active Record RecordInvalid # # Raised by <tt>save!</tt> and <tt>create!</tt> when the record is invalid. Use the # +record+ method to retrieve the record which did not validate. @@ -18,6 +18,13 @@ module ActiveRecord end end + # = Active Record Validations + # + # Active Record includes the majority of its validations from ActiveModel::Validations + # all of which accept the <tt>:on</tt> argument to define the context where the + # validations are active. Active Record will always supply either the context of + # <tt>:create</tt> or <tt>:update</tt> dependent on whether the model is a + # <tt>new_record?</tt>. module Validations extend ActiveSupport::Concern include ActiveModel::Validations @@ -50,6 +57,13 @@ module ActiveRecord end # Runs all the specified validations and returns true if no errors were added otherwise false. + # + # ==== Arguments + # + # * <tt>context</tt> - Context to scope the execution of the validations. Default is <tt>nil</tt>. + # If <tt>nil</tt> then the response of <tt>new_record?</tt> will determine the context. If <tt>new_record?</tt> + # returns true the the context will be <tt>:create</tt>, otherwise <tt>:update</tt>. Validation contexts + # for each validation can be defined using the <tt>:on</tt> option def valid?(context = nil) context ||= (new_record? ? :create : :update) output = super(context) diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb index 183acd73b8..0f5f2a6e99 100644 --- a/activerecord/lib/active_record/validations/associated.rb +++ b/activerecord/lib/active_record/validations/associated.rb @@ -33,7 +33,7 @@ module ActiveRecord # # Configuration options: # * <tt>:message</tt> - A custom error message (default is: "is invalid") - # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>). + # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>nil</tt>, other options <tt>:create</tt>, <tt>:update</tt>). # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The # method, proc or string should return or evaluate to a true or false value. |