# Interesting idea

**URL:** <https://www.ruby-forum.com/t/interesting-idea/103192>\
**Category:** Rails\
**Created:** [May 2, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/interesting-idea/103192 "2007-05-02T20:28:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c6cbf5/32.png) [@zeka](https://www.ruby-forum.com/u/zeka)\
**Post date:** [May 2, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/interesting-idea/103192/1 "2007-05-02T20:28:01Z")

</div>

Hey guys,

There is something I have been trying to implement but so far no luck.  
Basically, I want to have helpers that generate HTML around given  
content, similar to ActionView’s form\_for. Besides, I want to keep  
that “framing” HTML in separate files, similar to templates.

Ideally I’d even love to suggest it as a feature for Rails. Let me  
show you an example.  
This is what I want to have in my rhtml file:

\<% bubble\_block :corners =\> “round”, :color =\> “brown” do %\>

My content
\<% end %\>

So far I have tried the following: I added a method to my application  
helper:

def bubble\_block(options, &proc)  
raise ArgumentError, “No block given” unless block\_given?  
rendered\_html = render(:partial =\> “/templates/bubble”, :locals =\>  
{:block =\> proc} )  
concat rendered\_html, proc.binding  
end

This is how \_bubble.rhtml looks like:

\<% block.call %\>

What happens is _ALMOST_ what I want, except my block gets rendered  
twice. The output looks like this:

My content

My content

What am I missing? Thank you!

---

<div class="post-metadata">

**Author:** ![zeka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c6cbf5/32.png) [@zeka](https://www.ruby-forum.com/u/zeka)\
**Post date:** [May 2, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/interesting-idea/103192/2 "2007-05-02T20:52:06Z")

</div>

On May 2, 2007, at 2:26 PM, zeka wrote:

> {:block =\> proc} )  
> twice. The output looks like this:
> 
> My content
> 
> My content
> 
> What am I missing? Thank you!

Since you don’t say what options is supposed to do, perhaps this give  
you an idea of how to proceed:

def bubble\_block options={}, &block  
raise ArgumentError, “No block given” unless block\_given?  
content\_tag :div, {:id =\> ‘bubble’}.merge(options), &block  
end

and forget about the unnecessary \_bubble.rhtml

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![zeka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c6cbf5/32.png) [@zeka](https://www.ruby-forum.com/u/zeka)\
**Post date:** [May 2, 2007, 9:59pm UTC](https://www.ruby-forum.com/t/interesting-idea/103192/3 "2007-05-02T21:59:12Z")

</div>

Thank you for replying, Rob.

I already know how to do it without external .rhtml (I can use  
concat() inside of bubble\_for). However, the entire idea is about  
using external .rhtml files for surrounding HTML, since there is a lot  
of HTML and having that HTML embedded into ruby code is not practical  
(designers need to touch it).

What exactly in my implementation causes the wrapped block to render  
twice? Inside and outside of the surrounding HTML?
