diff options
Diffstat (limited to 'activemodel/lib/active_model/validations')
8 files changed, 13 insertions, 13 deletions
diff --git a/activemodel/lib/active_model/validations/acceptance.rb b/activemodel/lib/active_model/validations/acceptance.rb index ced083b312..26b12b504b 100644 --- a/activemodel/lib/active_model/validations/acceptance.rb +++ b/activemodel/lib/active_model/validations/acceptance.rb @@ -7,7 +7,7 @@ module ActiveModel def validate_each(record, attribute, value) unless value == options[:accept] - record.errors.add(attribute, :accepted, options) + record.errors.add(attribute, :accepted, :default => options[:message]) end end diff --git a/activemodel/lib/active_model/validations/confirmation.rb b/activemodel/lib/active_model/validations/confirmation.rb index 66bce0d2de..51445343f2 100644 --- a/activemodel/lib/active_model/validations/confirmation.rb +++ b/activemodel/lib/active_model/validations/confirmation.rb @@ -4,7 +4,7 @@ module ActiveModel def validate_each(record, attribute, value) confirmed = record.send(:"#{attribute}_confirmation") return if confirmed.nil? || value == confirmed - record.errors.add(attribute, :confirmation, options) + record.errors.add(attribute, :confirmation, :default => options[:message]) end def setup(klass) diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb index da4c84fbd6..2ee78f5dd2 100644 --- a/activemodel/lib/active_model/validations/exclusion.rb +++ b/activemodel/lib/active_model/validations/exclusion.rb @@ -8,7 +8,7 @@ module ActiveModel def validate_each(record, attribute, value) return unless options[:in].include?(value) - record.errors.add(attribute, :exclusion, options.merge(:value => value)) + record.errors.add(attribute, :exclusion, :default => options[:message], :value => value) end end diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb index 2667baa5a0..c34c860d4d 100644 --- a/activemodel/lib/active_model/validations/format.rb +++ b/activemodel/lib/active_model/validations/format.rb @@ -3,9 +3,9 @@ module ActiveModel class FormatValidator < EachValidator def validate_each(record, attribute, value) if options[:with] && value.to_s !~ options[:with] - record.errors.add(attribute, :invalid, options.merge(:value => value)) + record.errors.add(attribute, :invalid, :default => options[:message], :value => value) elsif options[:without] && value.to_s =~ options[:without] - record.errors.add(attribute, :invalid, options.merge(:value => value)) + record.errors.add(attribute, :invalid, :default => options[:message], :value => value) end end diff --git a/activemodel/lib/active_model/validations/inclusion.rb b/activemodel/lib/active_model/validations/inclusion.rb index 0ddf191b4f..446646d247 100644 --- a/activemodel/lib/active_model/validations/inclusion.rb +++ b/activemodel/lib/active_model/validations/inclusion.rb @@ -8,7 +8,7 @@ module ActiveModel def validate_each(record, attribute, value) return if options[:in].include?(value) - record.errors.add(attribute, :inclusion, options.merge(:value => value)) + record.errors.add(attribute, :inclusion, :default => options[:message], :value => value) end end diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 9b671f58de..d7218f4f52 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -37,7 +37,7 @@ module ActiveModel CHECKS.each do |key, validity_check| next unless check_value = options[key] - options[:message] ||= options[MESSAGES[key]] if options[MESSAGES[key]] + custom_message = options[:message] || options[MESSAGES[key]] valid_value = if key == :maximum value.nil? || value.size.send(validity_check, check_value) @@ -46,7 +46,7 @@ module ActiveModel end next if valid_value - record.errors.add(attribute, MESSAGES[key], options.merge(:count => check_value)) + record.errors.add(attribute, MESSAGES[key], :default => custom_message, :count => check_value) end end end diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb index d407258442..716010e88b 100644 --- a/activemodel/lib/active_model/validations/numericality.rb +++ b/activemodel/lib/active_model/validations/numericality.rb @@ -26,13 +26,13 @@ module ActiveModel return if options[:allow_nil] && raw_value.nil? unless value = parse_raw_value_as_a_number(raw_value) - record.errors.add(attr_name, :not_a_number, options.merge(:value => raw_value)) + record.errors.add(attr_name, :not_a_number, :value => raw_value, :default => options[:message]) return end if options[:only_integer] unless value = parse_raw_value_as_an_integer(raw_value) - record.errors.add(attr_name, :not_an_integer, options.merge(:value => raw_value)) + record.errors.add(attr_name, :not_an_integer, :value => raw_value, :default => options[:message]) return end end @@ -41,14 +41,14 @@ module ActiveModel case option when :odd, :even unless value.to_i.send(CHECKS[option]) - record.errors.add(attr_name, option, options.merge(:value => value)) + record.errors.add(attr_name, option, :value => value, :default => options[:message]) end else option_value = option_value.call(record) if option_value.is_a?(Proc) option_value = record.send(option_value) if option_value.is_a?(Symbol) unless value.send(CHECKS[option], option_value) - record.errors.add(attr_name, option, options.merge(:value => value, :count => option_value)) + record.errors.add(attr_name, option, :default => options[:message], :value => value, :count => option_value) end end end diff --git a/activemodel/lib/active_model/validations/presence.rb b/activemodel/lib/active_model/validations/presence.rb index 2826a10ffe..b319f4834b 100644 --- a/activemodel/lib/active_model/validations/presence.rb +++ b/activemodel/lib/active_model/validations/presence.rb @@ -4,7 +4,7 @@ module ActiveModel module Validations class PresenceValidator < EachValidator def validate(record) - record.errors.add_on_blank(attributes, options) + record.errors.add_on_blank(attributes, options[:message]) end end |