title: Cannot cache from decorator (draper)
body: <p>Caching is by far the most logic-intensive part of my view code, so I would like to do fragment caching from inside a decorator, however, I cant do it.</p>
  
  <p>When i do this from my decorator:</p>
  
  <pre><code>def cached_name
    h.cache do
     "a name here"
    end
  end
  </code></pre>
  
  <p>I get this:</p>
  
  <blockquote>
    <p>You have a nil object when you didn't expect it! You might have
    expected an instance of Array. The error occurred while evaluating
    nil.length</p>
  </blockquote>
  
  <p>I instantiate my decorator from inside a controller</p>
  
  <pre><code>@presenter = SomePresenter::new
  </code></pre>
  
  <p>I am using HAML for my views</p>
  
  <p>How can I succesfully cache from inside my decorator, so my view can do stuff like this</p>
  
  <pre><code>= @decorator.cached_logic_heavy_stuff
  </code></pre>
  
  <p><em>UPDATE:</em> I have created a git repo showing my issue: <a href="https://github.com/houen/presenter_caching" rel="nofollow">https://github.com/houen/presenter_caching</a></p>
  
  <p>UPDATE: This maybe works - see the repo</p>
  
  <pre><code>  include Haml::Helpers
    def another_way_to_try
      self.init_haml_helpers
      buffer = haml_buffer.buffer
  
      h.with_output_buffer(buffer) do
        h.cache do
          h.concat "i should still not be empty"
        end
      end
    end
  </code></pre>