padrino/padrino-contrib — pull request #17 by hongliang-goudou (2013-06-20 13:10:49+00:00)
Title: Let auto_locale handle root path "/" automatically. So the developers won't need to write their own special :index controller for redirect

Before, using auto_locale requires developers to do a redirect in the :index controller:
```ruby
get :index do
redirect url(:main)
end

get :main do
render "main"
end
```
Without this redirect, the index page would not have the ability to switch language. Because switch_to_lang helper method returns nothing but "/", not our expected "/en/" or "/zh_cn/". So to solve this problem, developers have to redirect "/" to another page, for the purpose of letting the url include the language parameter, for example, "/en/main".
So far it's all okay but only two flaws remains:
1. Every developer has to write their own :index redirect.
2. We have to modify auto_locale.rb to let it ignore root path while re-routing all the controllers' paths. (We already did that, @ujifgc has merged my last pull request #16.)
So a better solution comes to me. No need for every developer to write their own :index redirect. No need for auto_locale.rb to special treat root path while re-routing.
Now, developers can just let the :index controller be what it should be original. After they use the auto_locale plugin, everything would just work as fine. No extra changes are required. This is achieved by a special treatment inside the before filter of auto_locale.rb
For example, the index controller was something like:
```ruby
get :index do
render "index"
end
```
Before auto_locale is registered, a user visits the website by the domain "example.com", would return the page at the path "http://example.com/". After auto_locale is registered, the page would redirect to "http://example.com/en/" automatically and everything's just fine. No need to change the index controller code at all.
The default locale is guessed from the http Accept-Language header, or it would use the settings.locales[0].