svenfuchs/globalize3 — Issue #99: redirect without :locale
Author: Ian-Choi
Created: 2012-02-04 21:28:12+00:00
State: open

This might be a question related to i18n, but I guess users in here might have an answer.

I was following the rails guide to set up my i18n localization. I like to allow url without locale to use default locale and do not show locale in all the url.

For example,
/test/ # will work
/en/test # will also work

So I followed the instruction to do this:

# config/routes.rb
scope "(:locale)", :locale => /en|nl/ do
resources :tests
end

And this seems to work. However, when I perform a redirect in the controller, it will add the locale back to the url.
For example,
redirect_to new_test_path # in controller. index action

when hitting index with /test/, it redirect to /en/test/new

Does anyone know what is the best approach not add locale when using redirect_to? I still like the locale in the URL when the original url has the locale.

Aimed Behaviour:
1) (Yes) hitting index with /test/, redirect to /test/new
2) (Yes) hitting index with /en/test/, redirect to /en/test/new
3) (No) hitting index with /test/, redirect to /en/test/new
4) (No) hitting index with /en/test, redirect to /test/new