Using &block

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

How make for generate the block content?

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

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

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

Jason