From c6b4ef082f80255c1e3ec6e4feb1d199ed1e7efa Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 9 Feb 2011 08:31:22 -0800 Subject: use map rather than array concatenation --- activemodel/lib/active_model/errors.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 9d278220a8..04d996f78c 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -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 -- cgit v1.2.3