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?
stripped_length = value.strip.length
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
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
else
record.errors.add attribute, (options[:message] || "is required.")
record.errors.add attribute, (options[:message] || I18n.t('errors.messages.blank'))
end
end
end