aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/errors.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel/lib/active_model/errors.rb')
-rw-r--r--activemodel/lib/active_model/errors.rb10
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