# Routes, default\_url\_options and languages

**URL:** <https://www.ruby-forum.com/t/routes-default-url-options-and-languages/113957>\
**Category:** Rails\
**Created:** [September 6, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/routes-default-url-options-and-languages/113957 "2007-09-06T17:41:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [September 6, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/routes-default-url-options-and-languages/113957/1 "2007-09-06T17:41:23Z")

</div>

Hello,  
My app is available in 2 languages, English (en) and French (fr).

_I would like all my URLs to look like this :_  
/fr/companies  
/en/companies

_I’ve setup this route :_  
map.connect ‘:lg/:controller/:action/:id’

I don’t want to specify the :lg parameter in every url\_for calls.  
The language remains the same unless the params[:change\_lg] is set.

_In my application.rb, I’ve written this :_  
def default\_url\_options(options)  
{ :lg =\> params[:change\_lg].nil? ? session[:language] :  
params[:change\_lg] }  
end

_My problem :_  
When I use \<?=companies\_path ?\> in my view, here is the URL that is  
generated :  
/companies?lg=en

_What I would like to have instead :_  
/en/companies

Has anyone an idea?  
Would be much appreciated.

Thanks in advance,  
Thomas.

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [September 7, 2007, 3:21pm UTC](https://www.ruby-forum.com/t/routes-default-url-options-and-languages/113957/2 "2007-09-07T15:21:26Z")

</div>

you need to implement clean url that can be handled using a plugin from  
agile or u can also do it with the routes but then if there r many such  
links then its better to use plugin

in routes u need to write the controller:theaction which performs that  
task and then the variable something like ‘:controller/:action/:id’

hope this helps

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [September 10, 2007, 11:38am UTC](https://www.ruby-forum.com/t/routes-default-url-options-and-languages/113957/3 "2007-09-10T11:38:45Z")

</div>

Are you talking about a plugin I can find here  
[http://agilewebdevelopment.com](http://agilewebdevelopment.com) ?Which one are you talking about?

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [July 29, 2008, 5:11pm UTC](https://www.ruby-forum.com/t/routes-default-url-options-and-languages/113957/4 "2008-07-29T17:11:56Z")

</div>

Hi,

did you find a solution for this?

Cheers,  
derkaan

Thomas B. wrote:

> Are you talking about a plugin I can find here  
> [http://agilewebdevelopment.com](http://agilewebdevelopment.com) ?Which one are you talking about?
