# Using &block

**URL:** <https://www.ruby-forum.com/t/using-block/88830>\
**Category:** Rails\
**Created:** [March 14, 2007, 8:19pm UTC](https://www.ruby-forum.com/t/using-block/88830 "2007-03-14T20:19:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcelo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@marcelo](https://www.ruby-forum.com/u/marcelo)\
**Post date:** [March 14, 2007, 8:19pm UTC](https://www.ruby-forum.com/t/using-block/88830/1 "2007-03-14T20:19:28Z")

</div>

I am wanting make a helper for tag

. I am make follow.
1. def tabela(&block)
2. 

```
s = '<table>'

```

3. 

```
t = concat(s, block.binding)

```

4. 

```
t << '</table>'

```

5. end

And call this:

1. \<% tabela do %\>
2. 

```
teste</br>

```

3. 

```
teste2</br>

```

4. \<% end %\>

However this generate this code html

1. 

How make for generate the block content?

---

<div class="post-metadata">

**Author:** ![marcelo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@marcelo](https://www.ruby-forum.com/u/marcelo)\
**Post date:** [March 14, 2007, 8:24pm UTC](https://www.ruby-forum.com/t/using-block/88830/2 "2007-03-14T20:24:05Z")

</div>

Marcelo wrote:

> I am wanting make a helper for tag
> 
> . I am make follow.
> 
> 1. def tabela(&block)
> 2. 
> 
> ```
> s = '<table>'
> 
> ```
> 
> 3. 
> 
> ```
> t = concat(s, block.binding)
> 
> ```
> 
> 4. 
> 
> ```
> t << '</table>'
> 
> ```
> 
> 5. end
> 
> And call this:
> 
> 1. \<% tabela do %\>
> 2. 
> 
> ```
> teste</br>
> 
> ```
> 
> 3. 
> 
> ```
> teste2</br>
> 
> ```
> 
> 4. \<% end %\>
> 
> However this generate this code html
> 
> 1. 
> 
> How make for generate the block content?

Your not actually executing the block. You need to “capture” the block,  
and then call “concat” on the whole string.

See my blog post about block taking helpers for more info:  
[http://beautifulpixel.com/articles/2007/02/23/helpers-and-blocks](http://beautifulpixel.com/articles/2007/02/23/helpers-and-blocks)

---

<div class="post-metadata">

**Author:** ![marcelo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@marcelo](https://www.ruby-forum.com/u/marcelo)\
**Post date:** [March 14, 2007, 8:53pm UTC](https://www.ruby-forum.com/t/using-block/88830/3 "2007-03-14T20:53:07Z")

</div>

Try block.call. #binding only gets you the current variable binding and  
scope of the block, nothing gets executed.

Jason
