Commit c4814eb620ee6475461acc171754092b3bfb4af9
1 parent
9a571321
[Colab] Optional subdirectory route
Showing
2 changed files
with
14 additions
and
4 deletions
Show diff stats
app/controllers/application_controller.rb
@@ -16,17 +16,25 @@ class ApplicationController < ActionController::Base | @@ -16,17 +16,25 @@ class ApplicationController < ActionController::Base | ||
16 | class << self | 16 | class << self |
17 | # This is necessary for correct devise routing with locales: https://github.com/plataformatec/devise/wiki/How-To:--Redirect-with-locale-after-authentication-failure | 17 | # This is necessary for correct devise routing with locales: https://github.com/plataformatec/devise/wiki/How-To:--Redirect-with-locale-after-authentication-failure |
18 | def default_url_options | 18 | def default_url_options |
19 | - locale_options | 19 | + default = {} |
20 | + default.merge!(locale_options) | ||
21 | + default.merge!(subdirectory_options) | ||
20 | end | 22 | end |
21 | 23 | ||
22 | def locale_options | 24 | def locale_options |
23 | { locale: I18n.locale } | 25 | { locale: I18n.locale } |
24 | end | 26 | end |
27 | + | ||
28 | + def subdirectory_options | ||
29 | + { subdirectory: 'mezuro' } | ||
30 | + end | ||
25 | end | 31 | end |
26 | 32 | ||
27 | # This happens after the *_url *_path helpers | 33 | # This happens after the *_url *_path helpers |
28 | def default_url_options | 34 | def default_url_options |
29 | - self.class.locale_options | 35 | + default = {} |
36 | + default.merge!(self.class.locale_options) | ||
37 | + default.merge!(self.class.subdirectory_options) | ||
30 | end | 38 | end |
31 | 39 | ||
32 | protected | 40 | protected |
config/routes.rb
1 | Rails.application.routes.draw do | 1 | Rails.application.routes.draw do |
2 | - scope "mezuro" do | 2 | + scope "/(:subdirectory)", subdirectory: /mezuro/ do |
3 | scope "(:locale)", locale: /en|pt/ do | 3 | scope "(:locale)", locale: /en|pt/ do |
4 | # We need to manually define OmniAuth routes since the automatic generation does not support the dynamic scope | 4 | # We need to manually define OmniAuth routes since the automatic generation does not support the dynamic scope |
5 | devise_for :users, skip: :omniauth_callbacks | 5 | devise_for :users, skip: :omniauth_callbacks |
@@ -46,8 +46,10 @@ Rails.application.routes.draw do | @@ -46,8 +46,10 @@ Rails.application.routes.draw do | ||
46 | # Tutorials | 46 | # Tutorials |
47 | get '/tutorials/:name' => 'tutorials#view', as: 'tutorials' | 47 | get '/tutorials/:name' => 'tutorials#view', as: 'tutorials' |
48 | 48 | ||
49 | - root "home#index" | 49 | + root "home#index", as: 'locale_root' |
50 | end | 50 | end |
51 | + | ||
52 | + root "home#index" | ||
51 | end | 53 | end |
52 | 54 | ||
53 | # See comment above for devise_for | 55 | # See comment above for devise_for |