lib/jbuilder/jbuilder_template.rb in jbuilder-2.11.3 vs lib/jbuilder/jbuilder_template.rb in jbuilder-2.11.4

- old
+ new

@@ -139,13 +139,11 @@ def _render_partial_with_options(options) options.reverse_merge! locals: options.except(:partial, :as, :collection, :cached) options.reverse_merge! ::JbuilderTemplate.template_lookup_options as = options[:as] - if options.key?(:collection) && (options[:collection].nil? || options[:collection].empty?) - array! - elsif as && options.key?(:collection) && CollectionRenderer.supported? + if as && options.key?(:collection) && CollectionRenderer.supported? collection = options.delete(:collection) || [] partial = options.delete(:partial) options[:locals].merge!(json: self) if options.has_key?(:layout) @@ -154,12 +152,14 @@ if options.has_key?(:spacer_template) raise ::NotImplementedError, "The `:spacer_template' option is not supported in collection rendering." end - CollectionRenderer + results = CollectionRenderer .new(@context.lookup_context, options) { |&block| _scope(&block) } .render_collection_with_partial(collection, partial, @context, nil) + + array! if results.respond_to?(:body) && results.body.nil? elsif as && options.key?(:collection) && !CollectionRenderer.supported? # For Rails <= 5.2: as = as.to_sym collection = options.delete(:collection) locals = options.delete(:locals)