Forum: Ruby on Rails modifying bindings

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.
Avram D. (Guest)
on 2008-12-12 20:25
(Received via mailing list)
Hello,

I have a little challenge that is frustrating me. I am trying to write
a wrapper around cache() so that my fragments get cached with comments
injected at the front and back. Unfortunately it is not as simple as
using "concat(text,block.bindings)" before and after the call to
cache() because then the comments themselves don't get cached.

Here is what I have right now:

   def wrap_cache(path,&block)
     concat("<!-- start fragment for #{path} -->", block.binding)
     cache(path,&block)
     concat("<!-- end fragment for #{path} -->", block.binding)
   end

It produces the correct visual output, but the concat results aren't
part of the cached fragment, they are getting regenerated every time.
What I need to do is something like this:

   def wrap_cache2(path,&block)
     cache(path) do
       concat(label_frag('vvvvvvvvv',path),block.binding)
       yield
       concat(label_frag('^^^^^^^^^',path),block.binding)
     end
   end

But I need to give this new block the bindings of the original block,
rather than have it grab a new set of bindings. With the above,
cache() crashes b/c the inner block isn't in the context of an erb
template, so it's missing key stuff (specifically _erbout).

-Avram

"I realised something was wrong when I looked over and saw the mast in
the water." - Dean Barker, Team New Zealand skipper
This topic is locked and can not be replied to.