Reputation: 888
I asked a similar question recently, though that was aimed at having multiple blocks as arguments. This problem is a little more immediate.
The problem I have is, I have a helper method which I want to be able to pass content as a block to render. However, if I add more than one partial only the last one in the block is rendered. The methods are below.
def bootrap_panel(title, klass = 'primary', &block)
content_tag(:div, panel_heading(title) + panel_body(&block), class: 'panel panel-' + klass)
end
def panel_body(&block)
content_tag(:div, yield, class: 'panel-body') if block_given?
end
And an example of an issue I am having is here, where only the last partial is being displayed on the page.
=bootrap_panel 'Panels', 'primary' do
- render "dynamic_panels/partials/new"
- render "dynamic_panels/partials/dynamic_panels", dynamic_panels: dynamic_page.dynamic_panels
My first thought is, well I should be yielding the partials to an array or something first, then display that (I am not sure I am able to do that). Secondly, i am using the '-' operator instead of the '=' operator for displaying ruby content in haml. Why?
Upvotes: 4
Views: 523
Reputation: 18474
Pass the block itsef instead of its return value to content_tag:
content_tag(:div, class: 'panel-body', &block)
Other method:
content_tag(:div, capture(&block), class: 'panel-body')
Upvotes: 3