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



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'actionview/lib/action_view/renderer/collection_renderer.rb', line 130

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



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'actionview/lib/action_view/renderer/collection_renderer.rb', line 112

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