diff options
Diffstat (limited to 'config/routes.rb')
| -rw-r--r-- | config/routes.rb | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/config/routes.rb b/config/routes.rb index 9d4b41dc..2df9d463 100644 --- a/config/routes.rb +++ b/config/routes.rb | |||
| @@ -1,9 +1,23 @@ | |||
| 1 | Cccms::Application.routes.draw do | 1 | Cccms::Application.routes.draw do |
| 2 | 2 | ||
| 3 | # Provides the locale prefix url scheme | 3 | # Handles bare locale root paths: /de and /en (without trailing slash). |
| 4 | scope '(:locale)', locale: ->(v) { I18n.available_locales.map(&:to_s).include?(v) } do | 4 | # Must live outside and before the scope because the scope's /*page_path |
| 5 | # catch-all would otherwise consume these before the locale segment is | ||
| 6 | # recognised. Replaces routing-filter's around_recognize hook which | ||
| 7 | # handled this transparently. | ||
| 8 | get '/:locale', to: 'content#render_page', | ||
| 9 | defaults: { page_path: ['home'] }, | ||
| 10 | constraints: { locale: /de|en/ } | ||
| 5 | 11 | ||
| 6 | root :to => 'content#render_page', :page_path => ['home'], :locale => 'de' | 12 | # All application routes are scoped under an optional two-letter locale |
| 13 | # prefix: /de/... and /en/... Both forms are valid; the prefix is omitted | ||
| 14 | # for the default locale (:de) in generated URLs via default_url_options | ||
| 15 | # in ApplicationController. This replaces the routing-filter gem. | ||
| 16 | # | ||
| 17 | # The locale regex must be kept in sync with config/application.rb | ||
| 18 | # (config.i18n.available_locales) and ApplicationController#set_locale. | ||
| 19 | # Adding a new locale requires updating all three locations. | ||
| 20 | scope '(:locale)', locale: /de|en/ do | ||
| 7 | 21 | ||
| 8 | resources :tags | 22 | resources :tags |
| 9 | resources :occurrences | 23 | resources :occurrences |
| @@ -60,6 +74,14 @@ Cccms::Application.routes.draw do | |||
| 60 | match 'galleries/*page_path' => 'content#render_gallery', :via => :get | 74 | match 'galleries/*page_path' => 'content#render_gallery', :via => :get |
| 61 | match '/*page_path' => 'content#render_page', :as => :content, :via => :get | 75 | match '/*page_path' => 'content#render_page', :as => :content, :via => :get |
| 62 | 76 | ||
| 77 | # Handles /de/ and /en/ (locale root with trailing slash). | ||
| 78 | # The bare-slash case inside the scope is distinct from the /:locale | ||
| 79 | # route above due to trailing slash handling in Rack/Rails routing. | ||
| 80 | get '/', to: 'content#render_page', defaults: { page_path: ['home'] } | ||
| 81 | |||
| 82 | # Handles / (no locale prefix — default locale :de). | ||
| 83 | root to: 'content#render_page', defaults: { page_path: ['home'] } | ||
| 84 | |||
| 63 | end | 85 | end |
| 64 | 86 | ||
| 65 | end | 87 | end |
