# Url\_for and rake routes differences

**URL:** <https://www.ruby-forum.com/t/url-for-and-rake-routes-differences/170448>\
**Category:** Rails\
**Created:** [June 17, 2009, 6:51pm UTC](https://www.ruby-forum.com/t/url-for-and-rake-routes-differences/170448 "2009-06-17T18:51:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![diarmuid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/46a35a/32.png) [@diarmuid](https://www.ruby-forum.com/u/diarmuid)\
**Post date:** [June 17, 2009, 6:51pm UTC](https://www.ruby-forum.com/t/url-for-and-rake-routes-differences/170448/1 "2009-06-17T18:51:13Z")

</div>

I am caching and expiring pages/actions/fragments in my code and I’ve  
come across a really frustrating problem

In my routes I have prefixed all controllers with the :locale. This  
works well for the most part. When I cache a page/fragment it is  
cached to /en/whatever etc… as expected

However when I try to expire the page/fragment the locale is not  
prefixed to the url but added as an option ?locale=en (ie the  
routes.rb directive is ignored)

I inserted a url\_for statement into my controller to debug this issue  
and I see the same behaviour.

As a result the cached code is not being expired.

I have no idea what I am doing wrong

Here is a pastie with all the code [http://pastie.org/515309](http://pastie.org/515309)

Anyone have any ideas?

---

<div class="post-metadata">

**Author:** ![diarmuid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/46a35a/32.png) [@diarmuid](https://www.ruby-forum.com/u/diarmuid)\
**Post date:** [June 17, 2009, 7:26pm UTC](https://www.ruby-forum.com/t/url-for-and-rake-routes-differences/170448/2 "2009-06-17T19:26:24Z")

</div>

> I inserted a url\_for statement into my controller to debug this issue  
> and I see the same behaviour.
> 
> As a result the cached code is not being expired.
> 
> I have no idea what I am doing wrong
> 
> Here is a pastie with all the code [http://pastie.org/515309](http://pastie.org/515309)
> 
> Anyone have any ideas?

Not an answer, but perhaps a clue…

Found in vendor/rails/railties/guides/source/i18n.textile is this line:

Every helper method dependent on +url\_for+ (e.g. helpers for named  
routes like  
+root\_path+ or +root\_url+, resource routes like +books\_path+ or  
+books\_url+,  
etc.) will now _automatically include the locale in the query string_,  
like  
this: +http://localhost:3001/?locale=ja+.

-philip
