# Rails won't cache my action

**URL:** <https://www.ruby-forum.com/t/rails-wont-cache-my-action/93765>\
**Category:** Rails\
**Created:** [April 8, 2006, 10:39pm UTC](https://www.ruby-forum.com/t/rails-wont-cache-my-action/93765 "2006-04-08T22:39:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [April 8, 2006, 10:39pm UTC](https://www.ruby-forum.com/t/rails-wont-cache-my-action/93765/1 "2006-04-08T22:39:53Z")

</div>

I’ve decided to dive into page caching for my rails app. I’m doing my  
testing with webbrick and it refuses to display the cached page for a  
particular action. I’ve modified my paginator helper to put the page  
parameter in the url so that the paginated page can be used with  
caching. This works perfectly when the page parameter is in the url (ie  
browse/2006/2 or browse/2006/1). Both of those url put the cached file  
in public/browse/2006/1.html and 2.html. They work fine and webbrick  
displays the cached version. If I leave off the trailing 1 or 2 then  
the cached file is created in public/browse/2006.html. The file is  
getting created with each request instead of serving the cached version.  
What can I do to fix this problem. I’m running rails 1.1 Here is my  
routes.rb. I think it might have something to do with the problem.  
map.connect ‘pragmatic/browse/:id/:page’,  
:controller =\> ‘pragmatic’,  
:action =\> ‘browse\_date’,  
:requirements =\> { :page =\> /\d+/},  
:page =\> nil,  
:id =\> /\d\d\d\d/

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [April 8, 2006, 10:47pm UTC](https://www.ruby-forum.com/t/rails-wont-cache-my-action/93765/2 "2006-04-08T22:47:15Z")

</div>

Are you running in the development environment? Caching only works when  
your environment is production.

~ Ben

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [April 8, 2006, 10:47pm UTC](https://www.ruby-forum.com/t/rails-wont-cache-my-action/93765/3 "2006-04-08T22:47:16Z")

</div>

whoops… didn’t read all the way through… how are you setting up the  
caching in your controller?

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [April 8, 2006, 10:49pm UTC](https://www.ruby-forum.com/t/rails-wont-cache-my-action/93765/4 "2006-04-08T22:49:18Z")

</div>

Ben R. wrote:

> whoops… didn’t read all the way through… how are you setting up the  
> caching in your controller?

Here is my controler caching line  
caches\_page :index, :view, :browse, :browse\_date, :rss

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [April 9, 2006, 12:29am UTC](https://www.ruby-forum.com/t/rails-wont-cache-my-action/93765/5 "2006-04-09T00:29:42Z")

</div>

charlie bowman wrote:

> Ben R. wrote:
> 
> > whoops… didn’t read all the way through… how are you setting up the  
> > caching in your controller?
> 
> Here is my controler caching line  
> caches\_page :index, :view, :browse, :browse\_date, :rss

It turns out the problem is in the routes.rb  
I’m not sure why but I had to make the following change so that there  
the action portion of the route wasn’t hard coded. Maybe someone knows  
why this works but the previous example of mine didn’t.

map.connect ‘pragmatic/:action/:id/:page’,  
:controller =\> ‘pragmatic’,  
:requirements =\> { :page =\> /\d+/},  
:page =\> nil,  
:id =\> /\d\d\d\d/
