From 6bc1312e9ccb955c365069f1973cf3b158100924 Mon Sep 17 00:00:00 2001 From: Brave Hager Date: Mon, 13 May 2024 12:56:45 -0400 Subject: [PATCH 1/2] Ensure routes are loaded for URL helpers DSL compiler --- lib/tapioca/dsl/compilers/url_helpers.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tapioca/dsl/compilers/url_helpers.rb b/lib/tapioca/dsl/compilers/url_helpers.rb index 197315a77..eab1c6b0a 100644 --- a/lib/tapioca/dsl/compilers/url_helpers.rb +++ b/lib/tapioca/dsl/compilers/url_helpers.rb @@ -102,6 +102,9 @@ class << self def gather_constants return [] unless defined?(Rails.application) && Rails.application + routes_reloader = Rails.application.routes_reloader + routes_reloader.execute_unless_loaded if routes_reloader&.respond_to?(:execute_unless_loaded) + Object.const_set(:GeneratedUrlHelpersModule, Rails.application.routes.named_routes.url_helpers_module) Object.const_set(:GeneratedPathHelpersModule, Rails.application.routes.named_routes.path_helpers_module) From 191c0adadf15f6f4cd10970b905cac0b4c717822 Mon Sep 17 00:00:00 2001 From: Brave Hager Date: Mon, 13 May 2024 13:53:46 -0400 Subject: [PATCH 2/2] Add comment explaining deferred route drawing --- lib/tapioca/dsl/compilers/url_helpers.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tapioca/dsl/compilers/url_helpers.rb b/lib/tapioca/dsl/compilers/url_helpers.rb index eab1c6b0a..0e36b157b 100644 --- a/lib/tapioca/dsl/compilers/url_helpers.rb +++ b/lib/tapioca/dsl/compilers/url_helpers.rb @@ -102,6 +102,7 @@ class << self def gather_constants return [] unless defined?(Rails.application) && Rails.application + # Load routes if they haven't been loaded yet (see https://github.com/rails/rails/pull/51614). routes_reloader = Rails.application.routes_reloader routes_reloader.execute_unless_loaded if routes_reloader&.respond_to?(:execute_unless_loaded)