diff options
| -rw-r--r-- | app/helpers/link_helper.rb | 17 | ||||
| -rw-r--r-- | config/application.rb | 5 | ||||
| -rw-r--r-- | config/environments/production.rb | 1 | ||||
| -rw-r--r-- | config/routes.rb | 28 |
4 files changed, 46 insertions, 5 deletions
diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb index ea6c26f..878e8e4 100644 --- a/app/helpers/link_helper.rb +++ b/app/helpers/link_helper.rb | |||
| @@ -4,7 +4,7 @@ module LinkHelper | |||
| 4 | url_for( | 4 | url_for( |
| 5 | :controller => :content, | 5 | :controller => :content, |
| 6 | :action => :render_page, | 6 | :action => :render_page, |
| 7 | :locale => params[:locale] || I18n.locale, | 7 | :locale => (params[:locale] || I18n.locale).to_sym == I18n.default_locale ? nil : (params[:locale] || I18n.locale), |
| 8 | :page_path => path_array | 8 | :page_path => path_array |
| 9 | ) | 9 | ) |
| 10 | end | 10 | end |
| @@ -23,7 +23,7 @@ module LinkHelper | |||
| 23 | 23 | ||
| 24 | active_class = active ? {:class => 'active'} : {:class => 'inactive'} | 24 | active_class = active ? {:class => 'active'} : {:class => 'inactive'} |
| 25 | html_options = html_options.merge(active_class) | 25 | html_options = html_options.merge(active_class) |
| 26 | locale = params[:locale] || I18n.locale | 26 | locale = (params[:locale] || I18n.locale).to_sym == I18n.default_locale ? nil : (params[:locale] || I18n.locale) |
| 27 | 27 | ||
| 28 | link_to( | 28 | link_to( |
| 29 | title, | 29 | title, |
| @@ -46,4 +46,17 @@ module LinkHelper | |||
| 46 | method: :put, | 46 | method: :put, |
| 47 | form: { data: { confirm: message } } | 47 | form: { data: { confirm: message } } |
| 48 | end | 48 | end |
| 49 | |||
| 50 | def content_path(page_path = nil, options = {}) | ||
| 51 | if page_path.is_a?(Hash) | ||
| 52 | options = page_path | ||
| 53 | page_path = options.delete(:page_path) | ||
| 54 | end | ||
| 55 | locale = options[:locale] || params[:locale] || I18n.locale | ||
| 56 | options[:locale] = (locale.to_sym == I18n.default_locale) ? nil : locale | ||
| 57 | Rails.application.routes.url_helpers.content_path( | ||
| 58 | Array(page_path).join("/").sub(/^\//, ""), | ||
| 59 | options | ||
| 60 | ) | ||
| 61 | end | ||
| 49 | end | 62 | end |
diff --git a/config/application.rb b/config/application.rb index 3ddad2d..0be3396 100644 --- a/config/application.rb +++ b/config/application.rb | |||
| @@ -9,6 +9,10 @@ module Cccms | |||
| 9 | config.load_defaults 8.1 | 9 | config.load_defaults 8.1 |
| 10 | 10 | ||
| 11 | config.autoload_lib(ignore: %w[assets tasks]) | 11 | config.autoload_lib(ignore: %w[assets tasks]) |
| 12 | Rails.autoloaders.main.ignore( | ||
| 13 | Rails.root.join('lib/chaos_importer.rb'), | ||
| 14 | Rails.root.join('lib/update_importer.rb') | ||
| 15 | ) | ||
| 12 | 16 | ||
| 13 | config.time_zone = 'Berlin' | 17 | config.time_zone = 'Berlin' |
| 14 | 18 | ||
| @@ -16,5 +20,6 @@ module Cccms | |||
| 16 | config.i18n.fallbacks = { en: [:en, :de] } | 20 | config.i18n.fallbacks = { en: [:en, :de] } |
| 17 | 21 | ||
| 18 | config.filter_parameters += [:password, :password_confirmation] | 22 | config.filter_parameters += [:password, :password_confirmation] |
| 23 | config.active_storage.variant_processor = :disabled | ||
| 19 | end | 24 | end |
| 20 | end | 25 | end |
diff --git a/config/environments/production.rb b/config/environments/production.rb index f8d078e..fced949 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb | |||
| @@ -27,6 +27,7 @@ Rails.application.configure do | |||
| 27 | 27 | ||
| 28 | config.i18n.fallbacks = true | 28 | config.i18n.fallbacks = true |
| 29 | 29 | ||
| 30 | config.assets.css_compressor = nil | ||
| 30 | config.active_record.dump_schema_after_migration = false | 31 | config.active_record.dump_schema_after_migration = false |
| 31 | config.active_record.attributes_for_inspect = [ :id ] | 32 | config.active_record.attributes_for_inspect = [ :id ] |
| 32 | end | 33 | end |
diff --git a/config/routes.rb b/config/routes.rb index 9d4b41d..2df9d46 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 |
