Problem with route defaults and caching


I’m having a problem with routes and caching.

I have two routes set up as follows in my route file…

map.connect ‘stats’, :controller => ‘stats’, :action => ‘index’
map.connect ‘stats/:type’, :controller => ‘stats’, :action => ‘index’,
:defaults => {:type => nil}

When I use cache_action, the :type is never added to the url for
caching. All the cached names are simply ‘/stats’ even if a :type is

If I remove the first route, leaving just this…

map.connect ‘stats/:type’, :controller => ‘stats’, :action => ‘index’,
:defaults => {:type => nil}

my cached names now use the :type properly… ‘/stats/stat_type’

But now the problem is that any links I have in my view for my stats
controller always add the :type even if I didn’t specify it.

So if I load the page with the url ‘stats/stat_type’, urls generated for
the stats controller append the :type even if I didn’t specify it.

Ex.) link_to ‘test’, :action => ‘index’ results in ‘stats/stat_type’

I don’t want the :type included if I didn’t specify it. Does anybody
have any idea what’s wrong with my routes?


Turns out I need to pass :type => nil to link_to in order to force the
value… simply leaving it out isn’t good enough.