From 3c61e1ad475c58ef5df3e2b3b903becf87559010 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 18 Dec 2024 17:05:35 +0100 Subject: [PATCH] [Admin] Use Rails.application.mounted_helpers in base component Rather than implementing routing proxies ourselves, we can use what Rails offers. Fixes #6038 --- .../components/solidus_admin/base_component.rb | 18 ------------------ admin/lib/solidus_admin/engine.rb | 6 ++++++ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/admin/app/components/solidus_admin/base_component.rb b/admin/app/components/solidus_admin/base_component.rb index e3adf62c02f..ba8997e1cd9 100644 --- a/admin/app/components/solidus_admin/base_component.rb +++ b/admin/app/components/solidus_admin/base_component.rb @@ -37,23 +37,5 @@ def self.stimulus_id end delegate :stimulus_id, to: :class - - class << self - private - - def engines_with_routes - Rails::Engine.subclasses.map(&:instance).reject do |engine| - engine.routes.empty? - end - end - end - - # For each engine with routes, define a method that returns the routes proxy. - # This allows us to use the routes in the context of a component class. - engines_with_routes.each do |engine| - define_method(engine.engine_name) do - engine.routes.url_helpers - end - end end end diff --git a/admin/lib/solidus_admin/engine.rb b/admin/lib/solidus_admin/engine.rb index 3ad1f087b07..82b1ec3e4ad 100644 --- a/admin/lib/solidus_admin/engine.rb +++ b/admin/lib/solidus_admin/engine.rb @@ -63,5 +63,11 @@ class Engine < ::Rails::Engine SolidusAdmin::Engine.root.join("app/components"), ] end + + initializer "solidus_admin.routing_proxies" do |app| + ActiveSupport.on_load(:after_routes_loaded) do + SolidusAdmin::BaseComponent.include app.routes.mounted_helpers + end + end end end