Action caching: how to prevent cached request being wrapped with layout when originally rendered wit

Hi all,

I’ve run into a problem with action caching in Rails 3.2.1 and am
wondering if anyone can shed some light on the situation.

We are using caches_action with :layout => false for the #show action
on our controller.

The code for the action sometimes renders with the layout, and
sometimes without, eg:

if request.xhr?
render :action => “different_action”, :layout => false

render with layout


Subsequent cached requests to the code path where we originally
rendered :layout => false are now rendered with the layout. It seems
what Rails is doing is seeing that you didn’t cache the layout
originally, and therefore wrapping each subsequent request with the
standard layout. What we want is for the layout not to be rendered.

This caching was (allegedly) working correctly in Rails 2.3, but I
haven’t looked into the old ActionController caching code yet to see

How should this sort of action be cached so that subsequent requests
don’t wrap the cached action body in the layout?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs