Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Action caching (blocker): undefined local variable or method `cache'

#4468

There is a bug here:

body = controller.render_to_string(:text => cache, :layout => true) unless @cache_layout

(Line 136 of action_controller/caching/actions.rb)

There is no cache variable declared, perhaps variable body is desired...

Here is the function context:

def filter(controller)
  path_options = if @cache_path.respond_to?(:call)
    controller.instance_exec(controller, &@cache_path)
  else
    @cache_path
  end

  cache_path = ActionCachePath.new(controller, path_options || {})

  body = controller.read_fragment(cache_path.path, @store_options)

  unless body
    controller.action_has_layout = false unless @cache_layout
    yield
    controller.action_has_layout = true
    body = controller._save_fragment(cache_path.path, @store_options)
  end

  body = controller.render_to_string(:text => cache, :layout => true) unless @cache_layout

  controller.response_body = body
  controller.content_type = Mime[cache_path.extension || :html]
end

Here is the link to the current implementation in master:

current implementation

Reported by ximus · April 24th, 2010 @ 01:56 PM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. ximus
    ximus

    Rails versions concerned are version 3.beta3 and current master branch

    April 24th, 2010 @ 01:58 PM

  2. ximus
    ximus

    Now that I think of it, you can trigger this as so:
    @@@ruby AnyController < ApplicationController
    caches_action :any_action # ... end

    
    

    April 24th, 2010 @ 02:33 PM

  3. ximus
    ximus

    Now that I think of it, you can trigger this as so:

    AnyController < ApplicationController
      caches_action :any_action 
      # ... 
    end
    

    with config.action_controller.perform_caching = true

    April 24th, 2010 @ 02:36 PM

  4. Neeraj Singh
    Neeraj Singh
    caches_action :index 
    

    Above code is working fine for me with rails3 edge.

    April 24th, 2010 @ 06:16 PM

  5. Paul Barry
    Paul Barry

    I'm using master aaaa1782b44c620cecb97238534a2bd2be5d365a and ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin10.3.0], MBARI 0x6770, Ruby Enterprise Edition 2010.01

    I have not been able to reproduce this problem with config.action_controller.perform_caching = true in the development environment. It is caching the action and serving the cached file.

    April 24th, 2010 @ 08:51 PM

  6. Ryan Bigg
    Ryan Bigg

    Ximus, can you still replicate this?

    April 25th, 2010 @ 12:16 AM

  7. Ryan Bigg
    Ryan Bigg
    • State changed from new to open

    April 25th, 2010 @ 12:19 AM

  8. ximus
    ximus

    I overlooked something, it happens when you specify :layout => false

    AnyController < ApplicationController
      caches_action :any_action, :layout => false
      # ... 
    end
    

    Sorry about that, tried it against master just now and I'm getting the error message

    undefined local variable or method cache' for #<ActionController::Caching::Actions::ActionCacheFilter:...>

    Working with standard MRI 1.8.7 on osx.

    April 25th, 2010 @ 11:50 AM

  9. Ryan Bigg
    Ryan Bigg
    • State changed from open to incomplete

    Please submit a failing test case for this if you could.

    April 25th, 2010 @ 12:00 PM

  10. Neeraj Singh
    Neeraj Singh

    Attached is a patch which contains code change and tests.

    ActionCachingTestController catches all the exceptions and returns head 500. However most of the tests were not checking for response_code. Hence this bug was not caught in the test. All I had to do was to ensure that all tests check for response code.

    April 25th, 2010 @ 02:17 PM

  11. Neeraj Singh
    Neeraj Singh
    • Tag changed from actioncontroller, caching, rails3 to actioncontroller, caching, patch, rails3

    April 25th, 2010 @ 02:18 PM

  12. ximus
  13. José Valim
    José Valim
    • Milestone cleared.
    • State changed from incomplete to open
    • Assigned user set to José Valim

    April 27th, 2010 @ 11:53 AM

  14. Repository
    Repository
    • State changed from open to resolved

    (from [d793d30776737e46ead49d90dcba411c3dfd6edf]) ActionCachingTestController rescues from all exceptions. Making sure that all the tests check for valid response. [#4468 Action caching (blocker): undefined local variable or method `cache' state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/d793d30776737e46ead49d90dcba41...

    April 29th, 2010 @ 11:52 AM

  15. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM