aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-01-12 12:06:00 -0700
committerSean Griffin <sean@seantheprogrammer.com>2015-01-12 12:06:00 -0700
commit72570ea289ca96edbc074c3aadb2be2b214303af (patch)
tree4d4a62bc2679871216805fa1bf06272291abd9bd /activemodel/lib/active_model
parent0fee2d4085eb70fe7c15d5ddc2a378b93b815ab9 (diff)
parent140557e85fc43ef5cff81a3af748605a6870f45b (diff)
downloadrails-72570ea289ca96edbc074c3aadb2be2b214303af.tar.gz
rails-72570ea289ca96edbc074c3aadb2be2b214303af.tar.bz2
rails-72570ea289ca96edbc074c3aadb2be2b214303af.zip
Merge pull request #18439 from mokhan/validates-acceptance-of-array
allow '1' or true for acceptance validation.
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/validations/acceptance.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/validations/acceptance.rb b/activemodel/lib/active_model/validations/acceptance.rb
index ac5e79859b..ee160fb483 100644
--- a/activemodel/lib/active_model/validations/acceptance.rb
+++ b/activemodel/lib/active_model/validations/acceptance.rb
@@ -3,12 +3,12 @@ module ActiveModel
module Validations
class AcceptanceValidator < EachValidator # :nodoc:
def initialize(options)
- super({ allow_nil: true, accept: "1" }.merge!(options))
+ super({ allow_nil: true, accept: ["1", true] }.merge!(options))
setup!(options[:class])
end
def validate_each(record, attribute, value)
- unless value == options[:accept]
+ unless acceptable_option?(value)
record.errors.add(attribute, :accepted, options.except(:accept, :allow_nil))
end
end
@@ -20,6 +20,10 @@ module ActiveModel
klass.send(:attr_reader, *attr_readers)
klass.send(:attr_writer, *attr_writers)
end
+
+ def acceptable_option?(value)
+ Array(options[:accept]).include?(value)
+ end
end
module HelperMethods