views:

56

answers:

3

Before all, this question is about Rails 2.x.

I live in a spanish language country and the URLs for my web apps should be in spanish. I always created spanish spelled actions for my controllers until now, but that just turn off many of the advantages for using REST, like the built-in PUT method => edit action stuff.

So, I wanna know how to modify the routes.rb file for redirect all the traffic for all my existing and future resources without losing the RESTful standars.

Is this possible?

Example:

POST /inmuebles
:controller => inmuebles, :action => create

GET /inmuebles
:controller => inmuebles, :action => index

GET /inmuebles/nuevo
:controller => inmuebles, :action => new
+1  A: 

Use the :path_names option:

map.resources :inmeubles, :path_names => { :new => 'nuevo'}

Andrew Vit
I need to do this with all my resources, right?
Erik Escobedo
Oh wait... I need to do `map.resources :inmeubles` for all resources anyway, so it's just `:path_names => { :new => 'nuevo', :edit => 'editar'}` and so... isn't it?
Erik Escobedo
Yes, that's correct.
Andrew Vit
A: 

You can also try this i18n_routing gem http://github.com/kwi/i18n_routing

Mirko
+3  A: 

Piggy backing off of Andrew V's answer, but couldn't preview my comment...

Since all of your resources will likely have the same actions that need the same path names, you can use a with_options block to set these for all routes.

For example:

map.with_options :path_names => {:new => 'nuevo', :edit => 'editar'} do |rt|
  rt.resources :ineubles
  rt.resources :pollos
  rt.resources :gatos
end
Beerlington
Wow, wow, wow! If I do this, won't I have to declare `map.resources :gatos` anymore?
Erik Escobedo
Nope, you won't have to declare map.resources for any of the routes within this block. Using with_options essentially takes whatever its caller is (map), and passes that as the block variable, which I've called rt (short for route).
Beerlington