File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
activemodel/lib/active_model Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,25 @@ module Validations
45
45
extend HelperMethods
46
46
include HelperMethods
47
47
48
+ ##
49
+ # :method: validation_context
50
+ # Returns the context when running validations.
51
+ #
52
+ # This is useful when running validations except a certain context (opposite to the +on+ option).
53
+ #
54
+ # class Person
55
+ # include ActiveModel::Validations
56
+ #
57
+ # attr_accessor :name
58
+ # validates :name, presence: true, if: -> { validation_context != :custom }
59
+ # end
60
+ #
61
+ # person = Person.new
62
+ # person.valid? #=> false
63
+ # person.valid?(:new) #=> false
64
+ # person.valid?(:custom) #=> true
65
+
66
+ ##
48
67
attr_accessor :validation_context
49
68
private :validation_context=
50
69
define_callbacks :validate , scope : :name
You can’t perform that action at this time.
0 commit comments