Commit 5a337d1a3abfc8f9d789ec8efd6e41575a416f54
1 parent
f2788c39
[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 | 16 | class << self |
| 17 | 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 | 18 | def default_url_options |
| 19 | - locale_options | |
| 19 | + default = {} | |
| 20 | + default.merge!(locale_options) | |
| 21 | + default.merge!(subdirectory_options) | |
| 20 | 22 | end |
| 21 | 23 | |
| 22 | 24 | def locale_options |
| 23 | 25 | { locale: I18n.locale } |
| 24 | 26 | end |
| 27 | + | |
| 28 | + def subdirectory_options | |
| 29 | + { subdirectory: 'mezuro' } | |
| 30 | + end | |
| 25 | 31 | end |
| 26 | 32 | |
| 27 | 33 | # This happens after the *_url *_path helpers |
| 28 | 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 | 38 | end |
| 31 | 39 | |
| 32 | 40 | protected | ... | ... |
config/routes.rb
| 1 | 1 | Rails.application.routes.draw do |
| 2 | - scope "mezuro" do | |
| 2 | + scope "/(:subdirectory)", subdirectory: /mezuro/ do | |
| 3 | 3 | scope "(:locale)", locale: /en|pt/ do |
| 4 | 4 | # We need to manually define OmniAuth routes since the automatic generation does not support the dynamic scope |
| 5 | 5 | devise_for :users, skip: :omniauth_callbacks |
| ... | ... | @@ -40,8 +40,10 @@ Rails.application.routes.draw do |
| 40 | 40 | # Tutorials |
| 41 | 41 | get '/tutorials/:name' => 'tutorials#view', as: 'tutorials' |
| 42 | 42 | |
| 43 | - root "home#index" | |
| 43 | + root "home#index", as: 'locale_root' | |
| 44 | 44 | end |
| 45 | + | |
| 46 | + root "home#index" | |
| 45 | 47 | end |
| 46 | 48 | |
| 47 | 49 | # See comment above for devise_for | ... | ... |
-
mentioned in commit 6e5832bda02e4d7a7b7ccb0c1f8c144ed329f293
-
mentioned in commit 7541a31cc2a5e10d5c90770d043e485a5b487de1
-
mentioned in commit 5d29ba115773ff3ad8fc9d5d5f71fa11284edd45
-
mentioned in commit 299c12e63a240c7a855e7f3a34bcf7b14421f812
-
mentioned in commit 2222fb5785f5c0f95153a58bc1f8674751d933b7
-
mentioned in commit 3ac2af5c327b4acf214cde1eec70f8cb4370aecd
-
mentioned in commit 7950c5935df6844b544032c99cd5c63b8adcfa49
-
mentioned in commit e438ff3f7ffd8a7c3ce0109dc23677fa3de82783
-
mentioned in commit 14504bf4519257bcf12fe243e2ec3df690fbf5ab
-
mentioned in commit 6619a433e9ad4994e9e24ce13a0dcbefb66fe035
-
mentioned in commit e8c3009c1651db507c6c6bfe5fd0cf27a7b30e3f