Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
Store erb block and alter scope of erb block eval?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Steve V, post: 4467429"] 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 [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
Store erb block and alter scope of erb block eval?
Top