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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
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
else
  # render with layout
end

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/why.

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

Cheers,
-Jonathan.
This topic is locked and can not be replied to.