aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorThilo Utke <thilo@upstre.am>2010-11-28 14:36:40 +0100
committerJosé Valim <jose.valim@gmail.com>2010-12-01 11:43:37 +0100
commit7148b933c4865a5140187d7ed792fd6df9b860a4 (patch)
tree56f77db136192f65eb4e3a1417d8b989e56cfe37 /activemodel/lib
parent1ec126dd37b52ecf7c0c24a842fc87836d8f2e9b (diff)
downloadrails-7148b933c4865a5140187d7ed792fd6df9b860a4.tar.gz
rails-7148b933c4865a5140187d7ed792fd6df9b860a4.tar.bz2
rails-7148b933c4865a5140187d7ed792fd6df9b860a4.zip
ActiveModel::Errors.to_hash returns plain OrderedHash and used in to_json serialization to properly handle multiple errors per attribute [#5615 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/errors.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 99f47f2cbe..fdca852c7a 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -165,7 +165,13 @@ module ActiveModel
# Returns an ActiveSupport::OrderedHash that can be used as the JSON representation for this object.
def as_json(options=nil)
- self
+ to_hash
+ end
+
+ def to_hash
+ hash = ActiveSupport::OrderedHash.new
+ each { |k, v| (hash[k] ||= []) << v }
+ hash
end
# Adds +message+ to the error messages on +attribute+, which will be returned on a call to