# Helpers that take a block from the view

**URL:** <https://www.ruby-forum.com/t/helpers-that-take-a-block-from-the-view/77859>\
**Category:** Rails\
**Created:** [December 1, 2006, 2:03am UTC](https://www.ruby-forum.com/t/helpers-that-take-a-block-from-the-view/77859 "2006-12-01T02:03:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wycats](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/eb9ed0/32.png) [@wycats](https://www.ruby-forum.com/u/wycats)\
**Post date:** [December 1, 2006, 2:03am UTC](https://www.ruby-forum.com/t/helpers-that-take-a-block-from-the-view/77859/1 "2006-12-01T02:03:40Z")

</div>

I’m trying to build a helper that takes a block from the view (like  
form\_for).

Here’s what I have so far:

def basic\_filters &block  
html = Builder::XmlMarkup.new  
html.p(:class =\> “filters”) do  
html.button(:class =\> “filter\_change”) { html.img(:src =\>  
“/images/chop\_closed.gif”) }  
html \<\< “Advanced Filter …”  
end  
html.div(:class =\> “filters”) do  
html.button(:class =\> “filter\_change”) { html.img(:src =\>  
“/images/chop\_open.gif”) }  
html \<\< yield  
end  
concat(html, block.binding)  
end

It works fine, except that the yield call in the helper seems to render  
the block as well. So I end up with the block’s contents, followed by  
the return from the helper (which contains the block’s contents).

Any ideas?

---

<div class="post-metadata">

**Author:** ![wycats](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/eb9ed0/32.png) [@wycats](https://www.ruby-forum.com/u/wycats)\
**Post date:** [December 1, 2006, 2:28am UTC](https://www.ruby-forum.com/t/helpers-that-take-a-block-from-the-view/77859/2 "2006-12-01T02:28:18Z")

</div>

Yehuda K. wrote:

> def basic\_filters &block

> html \<\< yield

I thought a proc-style block gets called with block.call().

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![wycats](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/eb9ed0/32.png) [@wycats](https://www.ruby-forum.com/u/wycats)\
**Post date:** [December 1, 2006, 2:38am UTC](https://www.ruby-forum.com/t/helpers-that-take-a-block-from-the-view/77859/3 "2006-12-01T02:38:20Z")

</div>

Hi –

On Thu, 30 Nov 2006, Phlip wrote:

> Yehuda K. wrote:
> 
> > def basic\_filters &block
> 
> > html \<\< yield
> 
> I thought a proc-style block gets called with block.call().

It doesn’t have to; it can still be yielded to.

David

–  
David A. Black | removed\_email\_address@domain.invalid  
Author of “Ruby for Rails” [1] | Ruby/Rails training & consultancy [3]  
DABlog (DAB’s Weblog) [2] | Co-director, Ruby Central, Inc. [4]  
[1] [Ruby for Rails](http://www.manning.com/black) | [3] [http://www.rubypowerandlight.com](http://www.rubypowerandlight.com)  
[2] [http://dablog.rubypal.com](http://dablog.rubypal.com) | [4] [http://www.rubycentral.org](http://www.rubycentral.org)
