Class: ActionView::CollectionRenderer

Inherits:
PartialRenderer show all
Includes:
ObjectRendering
Defined in:
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 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



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/action_view/renderer/collection_renderer.rb', line 122

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



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/action_view/renderer/collection_renderer.rb', line 104

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