Flowdock
method

block_called_from_erb?

Importance_2
v2.3.2 - Show latest stable - 1 note - Class: ActionView::Helpers::TagHelper
block_called_from_erb?(block) private

Check whether we’re called from an erb template. We’d return a string in any other case, but erb <%= … %> can’t take an <% end %> later on, so we have to use <% … %> and implicitly concat.

Show source
Register or log in to add new notes.
March 25, 2009 - (>= v2.2.1)
1 thank

usage helper with block

helper example

def my_helper(&block)
  inner = capture(&block)
  out = "<somehtml>#{inner}</somehtml>"
  block_called_from_erb?(block) ? concat(out) : out
end

view example

<% my_helper do %>
  sometext
<% end %>

output

<somehtml>sometext</somehtml>

using ActionView::Helpers::CaptureHelper#capture