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

631d1677786f0725da6ccee46043686e?d=identicon&s=25 Jonathan Viney (jviney)
on 2012-02-07 09:38
(Received via mailing list)
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?

Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.