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"