From a9b666b51d28b2e74da630c31327dee7cbe96d37 Mon Sep 17 00:00:00 2001 From: Krekoten' Marjan Date: Tue, 30 Nov 2010 22:48:19 +0800 Subject: Fix generation of wrong json string when field has multiple errors --- activemodel/lib/active_model/errors.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 99f47f2cbe..01ca540d28 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -167,6 +167,16 @@ module ActiveModel def as_json(options=nil) self end + + def encode_json(encoder) + errors = [] + each_pair do |key, value| + value = value.first if value.size == 1 + errors << "#{encoder.encode(key.to_s)}:#{encoder.encode(value, false)}" + end + + "{#{errors * ','}}" + end # Adds +message+ to the error messages on +attribute+, which will be returned on a call to # on(attribute) for the same attribute. More than one error can be added to the same -- cgit v1.2.3