I have a rails helper method which I would like to pass two different blocks to be yielded in two different places in the method.
This is what I am trying to achieve in my view..
<%= collapsible_content do %>
<%= page_heading venue.title %>
<%- venues_facility_opening_times venue %>
<%-end %>
And this is the method itself
def collapsible_content(&block1, &block2)
content_tag(:div, nil, class: 'collapsible-content', data: { name: 'collapsible-1' }) do
content_tag(:div, nil, class: 'collapsible-content-item') do
concat button_tag(yield &block1, class: 'collapsible-content-toggle')
concat hidden_content(&block2)
end
end
end
private
def hidden_content(&block)
content_tag(:div, class: "collapsible-content-body") do
content_tag(:div, yield) if block_given?
end
end
However, from what i under stand the &block
is always for the last argument, so how is it possible to differentiate between where they yield?
I tried using a lambda, but ActiveSupport::SafeBuffer
prevents this.