Programming Language · 2017-12-12 0

no block given (yield) in partial [on hold]


Based on this answer, I have a partial located in foo/_bar.html.erb:

<div class="foo">
  <%= label %>: <%= capture($block) %>

I want to render it from the code, when calling another method, specifically a helper:

 def foo (label, &block)
   render 'foo/bar', locals: { label: label, block: block }

I call the foo helper like this:

<%= foo 'Hello world' do %>
<%= end %>

When running the code, I get this error:

no block given (yield)

(from the partial code)

If I remove the capture snippet, the label is rendered correctly.

How can I render the &block in the _bar partial?


def foo (label, &block) should be def foo(label, &block) (not sure if that’s the problem, though)
$ and & are two different symbols, capture($block) expects a global variable holding block.
@mudasobwa Ahh, typos! Thanks for spotting that! You can leave an answer. Maybe others will have the same issue in the future and will come here. :-)
– Ionică Bizău
5 hours ago
I doubt this particular case deserves it’s own answer 🙂
@IonicăBizău as you probably know, we close questions regarding problems that were caused by typos 😉


Would love your thoughts, please comment.x