# Layouts being cached?

**URL:** <https://www.ruby-forum.com/t/layouts-being-cached/108678>\
**Category:** Rails\
**Created:** [July 5, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/layouts-being-cached/108678 "2007-07-05T23:18:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@aaron](https://www.ruby-forum.com/u/aaron)\
**Post date:** [July 5, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/layouts-being-cached/108678/1 "2007-07-05T23:18:28Z")

</div>

I’m working on my spin of the age old shopping cart app. To help  
customers focus on checking out it seems reasonable enough to give  
them a simpler layout while they’re doing so. I added the following  
code to my app. You can assume that @mysession.checking\_out? is  
functioning correctly and returns either true or false depending on  
the users state at present. It is well tested.

So in development this works like a charm, no problems. Once I move  
it into production, the layout used is correctly selected the first  
hit, but all subsequent hits to that particular controller/action  
combination use that same layout regardless of state.

Production environment settings have not been altered, I’m not using  
any form of caching.

If you have any idea what is going on I’d appreciate your insight.

## Here’s the Code:----------------- class ApplicationController \< ActionController::Base … before\_filter :checkout? … def checkout? #if we are checking out and this isn’t a checkout activity but it is a get request, then… … if @mysession.checking\_out? self.class.layout “checkout” end … end

Thanks,  
Aaron

---

<div class="post-metadata">

**Author:** ![aaron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@aaron](https://www.ruby-forum.com/u/aaron)\
**Post date:** [July 5, 2007, 11:35pm UTC](https://www.ruby-forum.com/t/layouts-being-cached/108678/2 "2007-07-05T23:35:31Z")

</div>

> combination use that same layout regardless of state.  
> …  
> def checkout?  
> #if we are checking out and this isn’t a checkout activity but it  
> is a get request, then…  
> …  
> if @mysession.checking\_out?  
> self.class.layout “checkout”

else  
self.class.layout “the normal one”  
end

Rails saves the layout you define at the class level when it first  
reads/loads that class. So once you switch it, it’s never switching  
back.

-philip

---

<div class="post-metadata">

**Author:** ![aaron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@aaron](https://www.ruby-forum.com/u/aaron)\
**Post date:** [July 6, 2007, 2:39am UTC](https://www.ruby-forum.com/t/layouts-being-cached/108678/3 "2007-07-06T02:39:48Z")

</div>

Also - production env have cache set on default.
