Rails page caching trashes URLs

Hey all,

I’ve been tooling with a route where:


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:


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