# Action caching and redirects

**URL:** <https://www.ruby-forum.com/t/action-caching-and-redirects/113419>\
**Category:** Rails\
**Created:** [August 30, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/action-caching-and-redirects/113419 "2007-08-30T23:00:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [August 30, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/action-caching-and-redirects/113419/1 "2007-08-30T23:00:53Z")

</div>

I have some code that uses caches\_action to cache the output of a  
“show” method, and a before\_filter to redirect the user to a login  
page if the user hasn’t already logged in. Unfortunately, when  
redirect\_to method sends the user off to the login page, caches\_action  
saves that redirect, so that subsequent attempts to access the same  
“show” URL return a page that says “You are being redirected.”

Is there a way to stop the caching when a redirect occurs in a  
before\_filter?

Here’s some more detail, in case the above wasn’t clear:

1. The user attempts to go [http://csb-paul:3000/form/show/PHR](http://csb-paul:3000/form/show/PHR), and  
instead gets redirected to  
[http://csb-paul:3000/login/login](http://csb-paul:3000/login/login). So far, so good.

2. Once that happens, every attempt to get  
[http://csb-paul:3000/form/show/PHR](http://csb-paul:3000/form/show/PHR)  
(whether or not the user has logged in) returns a page that says “You  
are being redirected.” I put a debugging statement in my  
before\_filter, and it is not run once the page is cached (by  
caches\_action, which I thought was always supposed to run the before  
filters??)

Also, when #2 happens, I am getting a message in the log that says,  
“Filter chain halted as […filters.rb:597\>] did not yield.” I’m not  
sure if that is related to the problem.

Any helpful suggestions would be appreciated. Thanks,  
–Paul

---

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [October 25, 2007, 6:41am UTC](https://www.ruby-forum.com/t/action-caching-and-redirects/113419/2 "2007-10-25T06:41:15Z")

</div>

Don’t know if you’ve found a solution yet, but if you put in return  
false after the redirect\_to it won’t render the redirect page.

-mark
