diff options
author | Krekoten' Marjan <krekoten@gmail.com> | 2010-11-30 22:48:19 +0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-12-01 00:03:42 +0800 |
commit | a9b666b51d28b2e74da630c31327dee7cbe96d37 (patch) | |
tree | 5368f8025e154a17c1c91a72273162be359794c4 /activemodel/lib/active_model | |
parent | 76a15dd0599779f86bda063bb545bba68c6ff17b (diff) | |
download | rails-a9b666b51d28b2e74da630c31327dee7cbe96d37.tar.gz rails-a9b666b51d28b2e74da630c31327dee7cbe96d37.tar.bz2 rails-a9b666b51d28b2e74da630c31327dee7cbe96d37.zip |
Fix generation of wrong json string when field has multiple errors
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 10 |
1 files changed, 10 insertions, 0 deletions
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 # <tt>on(attribute)</tt> for the same attribute. More than one error can be added to the same |