From 4a01c22cb27e3a66ec82eea5365054bf992ef45e Mon Sep 17 00:00:00 2001 From: Roman Samoilov <2270393+rsamoilov@users.noreply.github.com> Date: Thu, 26 Mar 2026 18:33:43 +0000 Subject: [PATCH] Correctly load routes in Rails apps --- lib/rage/rails.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/rage/rails.rb b/lib/rage/rails.rb index 49fe46fb..27ca7bf8 100644 --- a/lib/rage/rails.rb +++ b/lib/rage/rails.rb @@ -54,4 +54,20 @@ def call(env) end end +# load deferred routes in Rails 8+ +if Rails::VERSION::MAJOR >= 8 + # reset Rage routes before Rails reloads routes + routes_reloader_patch = Module.new do + def reload! + Rage.__router.reset_routes + super + end + end + Rails::Application::RoutesReloader.prepend(routes_reloader_patch) + + Rails.application.config.after_initialize do + Rails.application.reload_routes! + end +end + require "rage/ext/setup"