From 4c22631a5a85b3082f0525cc2454d2bd2251922a Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sat, 27 Jun 2026 20:28:00 +0200 Subject: Fix routes after removing the routing-filter --- app/helpers/link_helper.rb | 17 +++++++++++++++-- config/application.rb | 5 +++++ config/environments/production.rb | 1 + 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 url_for( :controller => :content, :action => :render_page, - :locale => params[:locale] || I18n.locale, + :locale => (params[:locale] || I18n.locale).to_sym == I18n.default_locale ? nil : (params[:locale] || I18n.locale), :page_path => path_array ) end @@ -23,7 +23,7 @@ module LinkHelper active_class = active ? {:class => 'active'} : {:class => 'inactive'} html_options = html_options.merge(active_class) - locale = params[:locale] || I18n.locale + locale = (params[:locale] || I18n.locale).to_sym == I18n.default_locale ? nil : (params[:locale] || I18n.locale) link_to( title, @@ -46,4 +46,17 @@ module LinkHelper method: :put, form: { data: { confirm: message } } end + + def content_path(page_path = nil, options = {}) + if page_path.is_a?(Hash) + options = page_path + page_path = options.delete(:page_path) + end + locale = options[:locale] || params[:locale] || I18n.locale + options[:locale] = (locale.to_sym == I18n.default_locale) ? nil : locale + Rails.application.routes.url_helpers.content_path( + Array(page_path).join("/").sub(/^\//, ""), + options + ) + end 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 config.load_defaults 8.1 config.autoload_lib(ignore: %w[assets tasks]) + Rails.autoloaders.main.ignore( + Rails.root.join('lib/chaos_importer.rb'), + Rails.root.join('lib/update_importer.rb') + ) config.time_zone = 'Berlin' @@ -16,5 +20,6 @@ module Cccms config.i18n.fallbacks = { en: [:en, :de] } config.filter_parameters += [:password, :password_confirmation] + config.active_storage.variant_processor = :disabled end 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 config.i18n.fallbacks = true + config.assets.css_compressor = nil config.active_record.dump_schema_after_migration = false config.active_record.attributes_for_inspect = [ :id ] 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 @@ Cccms::Application.routes.draw do - # Provides the locale prefix url scheme - scope '(:locale)', locale: ->(v) { I18n.available_locales.map(&:to_s).include?(v) } do + # Handles bare locale root paths: /de and /en (without trailing slash). + # Must live outside and before the scope because the scope's /*page_path + # catch-all would otherwise consume these before the locale segment is + # recognised. Replaces routing-filter's around_recognize hook which + # handled this transparently. + get '/:locale', to: 'content#render_page', + defaults: { page_path: ['home'] }, + constraints: { locale: /de|en/ } - root :to => 'content#render_page', :page_path => ['home'], :locale => 'de' + # All application routes are scoped under an optional two-letter locale + # prefix: /de/... and /en/... Both forms are valid; the prefix is omitted + # for the default locale (:de) in generated URLs via default_url_options + # in ApplicationController. This replaces the routing-filter gem. + # + # The locale regex must be kept in sync with config/application.rb + # (config.i18n.available_locales) and ApplicationController#set_locale. + # Adding a new locale requires updating all three locations. + scope '(:locale)', locale: /de|en/ do resources :tags resources :occurrences @@ -60,6 +74,14 @@ Cccms::Application.routes.draw do match 'galleries/*page_path' => 'content#render_gallery', :via => :get match '/*page_path' => 'content#render_page', :as => :content, :via => :get + # Handles /de/ and /en/ (locale root with trailing slash). + # The bare-slash case inside the scope is distinct from the /:locale + # route above due to trailing slash handling in Rack/Rails routing. + get '/', to: 'content#render_page', defaults: { page_path: ['home'] } + + # Handles / (no locale prefix — default locale :de). + root to: 'content#render_page', defaults: { page_path: ['home'] } + end end -- cgit v1.3