aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-02-09 08:31:22 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-02-09 08:32:43 -0800
commitc6b4ef082f80255c1e3ec6e4feb1d199ed1e7efa (patch)
tree9cc9204d86e75ff7857f44153f3676525f01b676 /activemodel/lib
parent307e6b2b74ba3ae72602dc33e6d45cd3e46181c7 (diff)
downloadrails-c6b4ef082f80255c1e3ec6e4feb1d199ed1e7efa.tar.gz
rails-c6b4ef082f80255c1e3ec6e4feb1d199ed1e7efa.tar.bz2
rails-c6b4ef082f80255c1e3ec6e4feb1d199ed1e7efa.zip
use map rather than array concatenation
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/errors.rb13
1 files changed, 4 insertions, 9 deletions
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