# Rails page caching trashes URLs

**URL:** <https://www.ruby-forum.com/t/rails-page-caching-trashes-urls/103744>\
**Category:** Rails\
**Created:** [May 9, 2007, 8:58pm UTC](https://www.ruby-forum.com/t/rails-page-caching-trashes-urls/103744 "2007-05-09T20:58:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [May 9, 2007, 8:58pm UTC](https://www.ruby-forum.com/t/rails-page-caching-trashes-urls/103744/1 "2007-05-09T20:58:38Z")

</div>

Hey all,

I’ve been tooling with a route where:

‘/:controller/:action/:query’

query being a url escaped string, which I place in the URL with  
javascript. The idea is if a user submits the page without javascript,  
a normal ‘?query=foo’ is appended and the query page isn’t cached, but  
if the JS does run, the user gets a normal prettyish URL that can be  
page cached.

The problem is, given a query of:

‘kinnard city:“los angeles”’ (obviously ferret here)

javascript makes it into:

kinnard%20city%3A%22los%20angeles%22

which the controller handles smoothly. The page is cached, however, as:

kinnard+city:“los+angeles”.html (looks

That means subsequent requests will not hit the cached file, and instead  
will be run every time. I’m thinking this has to do with the  
re-generation of the URL for the cache file on line 133 of  
actionpack/lib/action\_controller/caching.rb :

self.class.cache\_page(content || response.body,  
url\_for(options.merge(:only\_path =\> true, :skip\_relative\_url\_root =\>  
true, :format =\> params[:format])))

Is there an issue with using a regex or some alternative? Maybe a way  
to stop url\_for from changing spaces into + signs?

Hm, answering my own question I might replace spaces with + signs inside  
the URL, but I wonder if my query will be read properly by the  
controller then. It still raises the oddness of Rails reading  
the :query one way, and caching it in a completely other one.

I’m sure this has been hit before, ideas?

–  
Matthew B. :: 607 227 0871  
Resume & Portfolio @ [http://madhatted.com](http://madhatted.com)
