1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

use map rather than array concatenation

This commit is contained in:
Aaron Patterson 2011-02-09 08:31:22 -08:00
parent 307e6b2b74
commit c6b4ef082f

View file

@ -245,26 +245,21 @@ module ActiveModel
# company.errors.full_messages # =>
# ["Name is too short (minimum is 5 characters)", "Name can't be blank", "Address can't be blank"]
def full_messages
full_messages = []
each do |attribute, messages|
map { |attribute, messages|
messages = Array.wrap(messages)
next if messages.empty?
if attribute == :base
full_messages.concat messages
messages
else
attr_name = attribute.to_s.gsub('.', '_').humanize
attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)
options = { :default => "%{attribute} %{message}", :attribute => attr_name }
full_messages.concat messages.map { |m|
messages.map { |m|
I18n.t(:"errors.format", options.merge(:message => m))
}
end
end
full_messages
}.flatten
end
# Translates an error message in its default scope