From: Steve V Date: 2005-04-21T06:04:59+09:00 Subject: Re: Store erb block and alter scope of erb block eval? > > Can you be more specific about what you are doing? I don't understand > what you mean by "capture a block from an rhtml page". > > Could you provide your full code showing the problem you are having? > > (I'm not an ERb expert, so I'm probably missing some way of using it > that I've not seen before.) Hmm, okay. As you will see from using the below. The <%=@title%> value will only be taken from the value in the TestController. No matter what I do, I cannot get the @title variable set in the TableBuilder class to be the one that is used. Steve test.rhtml: <%tb = TableBuilder.new("Table Title") tb.header_template do%> This is the header template <%=@title%> <%end%> <%=tb.render()%> test_controller.rb: class TestController < ApplicationController def test() #uncomment, and the title variable will # be used in the template #@title = "controller title" end end class TableBuilder def initialize(title = "") @title = title end def header_template(&block) @headerTemplate = block end def render() out = "" #do table building stuff. _erbout = "" #the below is taken from capture_helper.rb in # rails action_view\helpers buffer = eval("_erbout", @headerTemplate) pos = buffer.length @headerTemplate.call(binding) out << buffer[pos..-1] buffer[pos..-1] = "" #do other table building stuff return out end end