cache block at beginning of view fragment #6379

Closed
foxycoder opened this Issue May 18, 2012 · 5 comments

Comments

Projects
None yet
4 participants

It seems that whenever I try to put a cache block at the beginning of a view fragment I get the following error:

Exception: undefined method `length' for nil:NilClass

Example of a view:

/ views/layouts/_header.haml

- cache [ "v1" "header"] do
  %header
    %h1 Header title

I traced the error to the following code in the cache helper:

# actionpack-3.2.2/lib/action_view/helpers/cache_helper.rb -- line 47 to 56

          if fragment = controller.read_fragment(name, options)
            fragment
          else
            # VIEW TODO: Make #capture usable outside of ERB
            # This dance is needed because Builder can't use capture
            pos = output_buffer.length # <= THIS is where output_buffer is nil.
            yield
            output_safe = output_buffer.html_safe?
            fragment = output_buffer.slice!(pos..-1)
            if output_safe

It seems that output_buffer is sometimes nil. Is this a bug or am I doing something wrong here?

Gem versions:

  • Haml: 3.5.1
  • HamlRails: 0.3.4
  • Actionpack: 3.2.2
Contributor

KensoDev commented May 18, 2012

IMHO it's not a bug in Rails, I am having the same issues with the Slim view engine, moving to ERB solved the issue.

Oh it's good to know that more people have this issue. I'll try and dig some more in Haml then..

It seems that while output_buffer = nil, haml_buffer.buffer holds the actual buffer we need here. I will move this issue to the Haml guys.

Thanks.

Owner

spastorino commented May 18, 2012

So can you close it here, please?

@foxycoder foxycoder closed this May 18, 2012

Contributor

norman commented May 18, 2012

I'm happy to look into this as a Haml issue. However, there's a TODO comment in the file which says it needs to be made to work outside of Erb, and it breaks Slim as well as Haml. Wouldn't that suggest that it should be investigated on the Rails side as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment