Helpers that take a block from the view

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?

Yehuda K. wrote:

def basic_filters &block

html << yield

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


Phlip
Redirecting... ← NOT a blog!!!

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 | [email protected]
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 | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org