aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorLuke Brown <luke.brown@customersure.com>2010-08-17 09:48:12 +0100
committerLuke Brown <luke.brown@customersure.com>2010-08-17 09:48:12 +0100
commit95ecc08a30c4f5e8e59608777e3d98adf28fa693 (patch)
tree64085c1999b1404a3795539b3620b88804a9c23a /railties
parent9a665aa6d24e56f7c990cbdcd9a6e43188f75f94 (diff)
downloadrails-95ecc08a30c4f5e8e59608777e3d98adf28fa693.tar.gz
rails-95ecc08a30c4f5e8e59608777e3d98adf28fa693.tar.bz2
rails-95ecc08a30c4f5e8e59608777e3d98adf28fa693.zip
Added an example and explaination for using an optional path scope for the locale
Diffstat (limited to 'railties')
-rw-r--r--railties/guides/source/i18n.textile11
1 files changed, 11 insertions, 0 deletions
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 1af51af80e..6018cc44c8 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -231,6 +231,17 @@ end
Now, when you call the +books_path+ method you should get +"/en/books"+ (for the default locale). An URL like +http://localhost:3001/nl/books+ should load the Netherlands locale, then, and following calls to +books_path+ should return +"/nl/books"+ (because the locale changed).
+If you don't want to force the use of a locale in your routes you can use an optional path scope (donated by the use brackets) like so:
+
+<ruby>
+# config/routes.rb
+scope "(:locale)", :locale => /en|nl/ do
+ resources :books
+end
+</ruby>
+
+With this approach you will not get a +Routing Error+ when accessing your resources such as +http://localhost:3001/books+ without a locale. This is useful for when you want to use the default locale when one is not specified.
+
Of course, you need to take special care of the root URL (usually "homepage" or "dashboard") of your application. An URL like +http://localhost:3001/nl+ will not work automatically, because the +root :to => "books#index"+ declaration in your +routes.rb+ doesn't take locale into account. (And rightly so: there's only one "root" URL.)
You would probably need to map URLs like these: