Action caching with params

I was attempting to cache an action that had a URL like this:

http://foo.com/controller/action?years[]=2005&years[]=2006&bar=5&baz=blue

which returns different data than, say

http://foo.com/controller/action?years[]=2004&years[]=2005&bar=6&baz=red

However, the cached fragment would always be named
foo.com:3000/controller/action.cache, no matter what parameters where
passed in, which would result in incorrect data being rendered on a
cached page.

I eventually tracked the culprit to ActionController::Base#url_for,
which the fragment cacher calls well reading and writing the fragment.
In my controller, I added this:

def url_for(options = nil, *parameters_for_method_reference)
super( options ? options : params, parameters_for_method_reference)
end

which sends the params hash as options, if no options are specified
(as is the case with the cacher).

So is this a bug in rails or a misunderstanding on my part as to the
proper behavior? Am I doing something dangerous here by fiddling with
one of the more used methods?

Thanks,
Andrew

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs