Class: ViewComponent::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/view_component/collection.rb

Instance Method Summary collapse

Instance Method Details

#render_in(view_context, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/view_component/collection.rb', line 5

def render_in(view_context, &block)
  iterator = ActionView::PartialIteration.new(@collection.size)

  @component.compile(raise_errors: true)
  @component.validate_collection_parameter!(validate_default: true)

  @collection.map do |item|
    content = @component.new(**component_options(item, iterator)).render_in(view_context, &block)
    iterator.iterate!
    content
  end.join.html_safe
end