Throw a descriptive error if attempting to serialize an array with Serializer not ArraySerializer #143

This commit is contained in:
Jean Boussier
2012-11-22 23:27:18 -05:00
parent 2fc083a1fe
commit 06e8218193
2 changed files with 15 additions and 0 deletions

View File

@@ -44,6 +44,11 @@ module ActionController
(json.respond_to?(:active_model_serializer) && json.active_model_serializer)
if json.respond_to?(:to_ary)
unless serializer <= ActiveModel::ArraySerializer
raise ArgumentError.new("#{serializer.name} is not an ArraySerializer. " +
"You may want to use the :each_serializer option instead.")
end
if options[:root] != false && serializer.root != false
# default root element for arrays is serializer's root or the controller name
# the serializer for an Array is ActiveModel::ArraySerializer