Fail if collection type cannot be inferred with json adapter (#2210)

This commit is contained in:
Joe Meredith
2017-10-30 08:33:31 -04:00
parent 88367da970
commit c6a14c9eac
3 changed files with 11 additions and 3 deletions

View File

@@ -46,7 +46,10 @@ module ActiveModel
# 3. get from collection name, if a named collection
key ||= object.respond_to?(:name) ? object.name && object.name.underscore : nil
# 4. key may be nil for empty collection and no serializer option
key && key.pluralize
key &&= key.pluralize
# 5. fail if the key cannot be determined
key || fail(ArgumentError, 'Cannot infer root key from collection type. Please
specify the root or each_serializer option, or render a JSON String')
end
# rubocop:enable Metrics/CyclomaticComplexity