@@ -66,8 +66,10 @@ module ClassMethods
66
66
# end
67
67
#
68
68
# Options:
69
- # * <tt>:on</tt> - Specifies the context where this validation is active
70
- # (e.g. <tt>on: :create</tt> or <tt>on: :custom_validation_context</tt>)
69
+ # * <tt>:on</tt> - Specifies the contexts where this validation is active.
70
+ # You can pass a symbol or an array of symbols.
71
+ # (e.g. <tt>on: :create</tt> or <tt>on: :custom_validation_context</tt> or
72
+ # <tt>on: [:create, :custom_validation_context]</tt>)
71
73
# * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
72
74
# * <tt>:allow_blank</tt> - Skip validation if attribute is blank.
73
75
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
@@ -124,8 +126,10 @@ def validates_each(*attr_names, &block)
124
126
# end
125
127
#
126
128
# Options:
127
- # * <tt>:on</tt> - Specifies the context where this validation is active
128
- # (e.g. <tt>on: :create</tt> or <tt>on: :custom_validation_context</tt>)
129
+ # * <tt>:on</tt> - Specifies the contexts where this validation is active.
130
+ # You can pass a symbol or an array of symbols.
131
+ # (e.g. <tt>on: :create</tt> or <tt>on: :custom_validation_context</tt> or
132
+ # <tt>on: [:create, :custom_validation_context]</tt>)
129
133
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
130
134
# if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
131
135
# or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
@@ -141,7 +145,7 @@ def validate(*args, &block)
141
145
options = options . dup
142
146
options [ :if ] = Array ( options [ :if ] )
143
147
options [ :if ] . unshift lambda { |o |
144
- o . validation_context == options [ :on ]
148
+ Array ( options [ :on ] ) . include? ( o . validation_context )
145
149
}
146
150
end
147
151
args << options
0 commit comments