add class attribute :root to ArraySerializer

You can now set the default behavior for Array serialization in a
single place
This commit is contained in:
Tee Parham
2012-07-14 21:44:23 -06:00
parent 56824f055b
commit 0832e42917
3 changed files with 47 additions and 5 deletions

View File

@@ -40,13 +40,17 @@ module ActionController
end
def _render_option_json(json, options)
if json.respond_to?(:to_ary)
options[:root] ||= controller_name unless options[:root] == false
end
serializer = options.delete(:serializer) ||
(json.respond_to?(:active_model_serializer) && json.active_model_serializer)
if json.respond_to?(:to_ary)
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
options[:root] ||= serializer.root || controller_name
end
end
if serializer
options[:scope] = serialization_scope
options[:url_options] = url_options