diff options
author | Dmitry Polushkin <dmitry.polushkin@gmail.com> | 2015-09-07 22:41:50 +0100 |
---|---|---|
committer | Dmitry Polushkin <dmitry.polushkin@gmail.com> | 2015-09-07 22:42:50 +0100 |
commit | e3d99e239dd1b59d31ac90f74186ded8b55de599 (patch) | |
tree | e0ce0816d764133343f1b5bbf6e19efd6bbb1c63 /activemodel/lib/active_model | |
parent | d1ce45cd8c77bea3c5b7d197a66f172ffcd5e6a6 (diff) | |
download | rails-e3d99e239dd1b59d31ac90f74186ded8b55de599.tar.gz rails-e3d99e239dd1b59d31ac90f74186ded8b55de599.tar.bz2 rails-e3d99e239dd1b59d31ac90f74186ded8b55de599.zip |
Validate multiple contexts on `valid?` and `invalid?` at once.
Example:
```ruby
class Person
include ActiveModel::Validations
attr_reader :name, :title
validates_presence_of :name, on: :create
validates_presence_of :title, on: :update
end
person = Person.new
person.valid?([:create, :update]) # => true
person.errors.messages # => {:name=>["can't be blank"], :title=>["can't be blank"]}
```
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/validations.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index 5f1dde4aa3..f23c920d87 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -162,7 +162,7 @@ module ActiveModel options = options.dup options[:if] = Array(options[:if]) options[:if].unshift ->(o) { - Array(options[:on]).include?(o.validation_context) + !(Array(options[:on]) & Array(o.validation_context)).empty? } end |