Using LengthValidator's localized messages for StrippedLengthValidator.

This commit is contained in:
Jeremy Banks 2013-02-18 21:57:46 -05:00
parent eb2a5e4654
commit d42782b318

View File

@ -3,12 +3,12 @@ class StrippedLengthValidator < ActiveModel::EachValidator
unless value.nil? unless value.nil?
stripped_length = value.strip.length stripped_length = value.strip.length
range = options[:in] range = options[:in]
record.errors.add attribute, (options[:message] || "is too short (minimum is #{range.begin}).") unless record.errors.add attribute, (options[:message] || I18n.t('errors.messages.too_short', count: range.begin)) unless
stripped_length >= range.begin stripped_length >= range.begin
record.errors.add attribute, (options[:message] || "is too long (maximum is #{range.end}).") unless record.errors.add attribute, (options[:message] || I18n.t('errors.messages.too_long', count: range.end)) unless
stripped_length <= range.end stripped_length <= range.end
else else
record.errors.add attribute, (options[:message] || "is required.") record.errors.add attribute, (options[:message] || I18n.t('errors.messages.blank'))
end end
end end
end end