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: 4467128"] Is there something special erb does when you capture a block from an rhtml page? I tried passing my own variable values to the block within my class(separate from the controller), and the values are ignored. I think the heart of the problem is that you're calling ERB.new on a regular string. I need to capture this information from an rhtml page. The only way I have found to do that is by using a "do" block. r.content do%> Test <%=@sometext%> <%end%> This gives me a block, and not a string. Is there a way to turn the contents of the returned proc as a string? to_s just gives me the memory location(?) of the proc object. The other question is why aren't my variables used for the block call when I'm in the class? Does it have something to do with the existing scope of the proc object? Can I change the scope? The only place I can get that @sometext value to be used from is within the controller. I have tried defining @sometext within my separate class, and passing that into the call, but nothing happens. def content(&block) @sometext = "sometext" @data = block.call(@sometext) end def render() return @data end The above will just render "Test ", and not use the specified value for @sometext. Steve [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
Store erb block and alter scope of erb block eval?
Top