From 2bb0abbec0e4abe843131f188129a1189b1bf714 Mon Sep 17 00:00:00 2001 From: Justin Weiss Date: Tue, 5 Aug 2014 13:13:40 -0700 Subject: Add a note on custom validation contexts. The documentation on `:on` for validations was inconsistent, and most only referenced the `:create` and `:update` contexts. I fixed those to be consistent with the documentation on `AM::Validations.validates`, which seemed to have the best docs. [ci skip] --- activerecord/lib/active_record/validations/associated.rb | 8 +++++--- activerecord/lib/active_record/validations/presence.rb | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb index b4785d3ba4..47ccef31a5 100644 --- a/activerecord/lib/active_record/validations/associated.rb +++ b/activerecord/lib/active_record/validations/associated.rb @@ -29,9 +29,11 @@ module ActiveRecord # Configuration options: # # * :message - A custom error message (default is: "is invalid"). - # * :on - Specifies when this validation is active. Runs in all - # validation contexts by default (+nil+), other options are :create - # and :update. + # * :on - Specifies the contexts where this validation is active. + # Runs in all validation contexts by default (nil). You can pass a symbol + # or an array of symbols. (e.g. on: :create or + # on: :custom_validation_context or + # on: [:create, :custom_validation_context]) # * :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, diff --git a/activerecord/lib/active_record/validations/presence.rb b/activerecord/lib/active_record/validations/presence.rb index e586744818..c7aa814ba8 100644 --- a/activerecord/lib/active_record/validations/presence.rb +++ b/activerecord/lib/active_record/validations/presence.rb @@ -44,9 +44,11 @@ module ActiveRecord # # 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. + # * :on - Specifies the contexts where this validation is active. + # Runs in all validation contexts by default (nil). You can pass a symbol + # or an array of symbols. (e.g. on: :create or + # on: :custom_validation_context or + # on: [:create, :custom_validation_context]) # * :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 -- cgit v1.2.3