Forum: Ruby on Rails Rails page caching trashes URLs

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
39b36b2be47228f8619d61ea7a607a25?d=identicon&s=25 Matthew Beale (mixonic)
on 2007-05-09 20:58
(Received via mailing list)
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 Beale :: 607 227 0871
Resume & Portfolio @
This topic is locked and can not be replied to.