Permalink
Browse files

Switch to using include? on validation callbacks

  • Loading branch information...
John Foley
John Foley committed Jul 3, 2012
1 parent d66d607 commit 60c65ca8dfc197b83f3b74b7e6ddeede005d416b
Showing with 2 additions and 2 deletions.
  1. +2 −2 activemodel/lib/active_model/validations/callbacks.rb
@@ -57,7 +57,7 @@ def before_validation(*args, &block)
if options.is_a?(Hash) && options[:on]
options[:if] = Array(options[:if])
options[:on] = Array(options[:on])
- options[:if].unshift("self.validation_context.in? #{options[:on]}")
+ options[:if].unshift("#{options[:on]}.include? self.validation_context")
end
set_callback(:validation, :before, *args, &block)
end
@@ -95,7 +95,7 @@ def after_validation(*args, &block)
options[:if] = Array(options[:if])
if options[:on]
options[:on] = Array(options[:on])
- options[:if].unshift("self.validation_context.in? #{options[:on]}")
+ options[:if].unshift("#{options[:on]}.include? self.validation_context")
end
set_callback(:validation, :after, *(args << options), &block)
end

1 comment on commit 60c65ca

@jordansexton

This comment has been minimized.

Show comment Hide comment
@jordansexton

jordansexton Aug 23, 2013

I realize this is a year old, but I notice that this change was made to ActiveModel::Validations::Callbacks, while ActiveModel::Validations still only checks against a single :on context.

What do you think about changing the validate method there to allow multiple contexts for all validators?

I realize this is a year old, but I notice that this change was made to ActiveModel::Validations::Callbacks, while ActiveModel::Validations still only checks against a single :on context.

What do you think about changing the validate method there to allow multiple contexts for all validators?

Please sign in to comment.