Forum: Ruby on Rails Need help with concat and binding

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2007-04-06 13:30
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...

<table>
  <tr>
    <th>bla</th>
  </tr>
  <tr>
    <td>bla2</td>
  </tr>
</table>

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
E04fb0aed034ea8b8400040cf8000a9e?d=identicon&s=25 sjs (Guest)
on 2007-04-10 19:39
(Received via mailing list)
Check out the usage here:
http://blog.imperialdune.com/2007/3/27/dirty-views...

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 Muheim <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.