Skip to content

Commit

Permalink
Switch to using include? on validation callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
John Foley committed Sep 23, 2012
1 parent d66d607 commit 60c65ca
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions activemodel/lib/active_model/validations/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

1 comment on commit 60c65ca

@jordaaash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.