Class: ActionView::CollectionRenderer

Inherits:
PartialRenderer show all
Includes:
ObjectRendering
Defined in:
actionview/lib/action_view/renderer/collection_renderer.rb

Overview

:nodoc:

Defined Under Namespace

Classes: CollectionIterator, MixedCollectionIterator, PreloadCollectionIterator, SameCollectionIterator

Instance Method Summary collapse

Methods inherited from PartialRenderer

#initialize, #render

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Methods inherited from AbstractRenderer

#initialize, #render

Constructor Details

This class inherits a constructor from ActionView::PartialRenderer

Instance Method Details

#render_collection_derive_partial(collection, context, block) ⇒ Object


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'actionview/lib/action_view/renderer/collection_renderer.rb', line 119

def render_collection_derive_partial(collection, context, block)
  paths = collection.map { |o| partial_path(o, context) }

  if paths.uniq.length == 1
    # Homogeneous
    render_collection_with_partial(collection, paths.first, context, block)
  else
    if @options[:cached]
      raise NotImplementedError, "render caching requires a template. Please specify a partial when rendering"
    end

    paths.map! { |path| retrieve_variable(path).unshift(path) }
    collection = MixedCollectionIterator.new(collection, paths)
    render_collection(collection, context, nil, nil, nil, block)
  end
end

#render_collection_with_partial(collection, partial, context, block) ⇒ Object


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'actionview/lib/action_view/renderer/collection_renderer.rb', line 100

def render_collection_with_partial(collection, partial, context, block)
  iter_vars  = retrieve_variable(partial)

  collection = if collection.respond_to?(:preload_associations)
    PreloadCollectionIterator.new(collection, partial, iter_vars, collection)
  else
    SameCollectionIterator.new(collection, partial, iter_vars)
  end


  template = find_template(partial, @locals.keys + iter_vars)

  layout = if !block && (layout = @options[:layout])
    find_template(layout.to_s, @locals.keys + iter_vars)
  end

  render_collection(collection, context, partial, template, layout, block)
end