# Need help with concat and binding

**URL:** <https://www.ruby-forum.com/t/need-help-with-concat-and-binding/91300>\
**Category:** Rails\
**Created:** [April 6, 2007, 1:30pm UTC](https://www.ruby-forum.com/t/need-help-with-concat-and-binding/91300 "2007-04-06T13:30:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 6, 2007, 1:30pm UTC](https://www.ruby-forum.com/t/need-help-with-concat-and-binding/91300/1 "2007-04-06T13:30:29Z")

</div>

Hi all

I want to create a HTML table builder that outputs HTML code.

\<% incense\_table do |table| -%\>  
\<% table.row do |row| -%\>  
\<%= row.header(‘bla’) %\>  
\<% end -%\>  
\<% table.row do |row| -%\>  
\<%= row.data(‘bla2’) %\>  
\<% end -%\>  
\<% end -%\>

…should result in…

| bla |
| --- |
| bla2 |

I’ve come so far (code is in application\_helper.rb):

module ApplicationHelper  
def incense\_table(options = {}, &block)  
yield(IncenseTableBuilder.new)  
end  
end

class IncenseTableBuilder  
include ActionView::Helpers::TextHelper

def row  
yield(IncenseTableBuilder::Row.new)  
end  
end

class IncenseTableBuilder::Row  
include ActionView::Helpers::TextHelper

def header(content, \*options)  
concat(content, block.binding)  
end

def data(content, \*options)  
concat(content, block.binding)  
end  
end

Sadly I don’t really get it how to use the concat method… I need a  
“binding” as 2nd parameter but don’t have a clue what this should be.

Anyone could show me a step or two into the right direction?

Thanks a lot,  
Josh

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 10, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/need-help-with-concat-and-binding/91300/2 "2007-04-10T19:39:46Z")

</div>

Check out the usage here:  
[http://blog.imperialdune.com/2007/3/27/dirty-views-clean-them-up](http://blog.imperialdune.com/2007/3/27/dirty-views-clean-them-up)

Basically you need to do something like:

def header(content, \*options, &block)  
concat(content, block.binding)  
end

Good luck.

-s

On Apr 6, 4:30 am, Joshua M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
