Skip to content

Build route helpers from the route set ActiveAdmin.routes draws into - #9154

Open
senid231 wants to merge 5 commits into
activeadmin:masterfrom
senid231:route-helpers-engine
Open

senid231 wants to merge 5 commits into
activeadmin:masterfrom
senid231:route-helpers-engine

Conversation

@senid231

@senid231 senid231 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Active Admin now builds its route helpers from the route set that ActiveAdmin.routes(self) is called in, so it works inside an engine's routes.draw. Until now, apps patched Helpers::Routes, BaseController and the Devise controllers to get there (#4294).

Decisions the diff doesn't show:

  • ActionDispatch::Routing::Mapper has no public reader for its route set in Rails 7.2 to 8.1, so Application#routes reads @set, falling back to the host routes. A spec fails if that breaks.
  • BaseController.inherited adds the engine's helpers to resource and page controllers. If controllers were loaded for another route set, ActiveAdmin.routes reloads them, so only one route set can host Active Admin. In an engine app on Rails 7.2 and 8.1, the engine's routes trigger the first load, so Active Admin and its before_load and after_load hooks still run once. A second load happens only if something loads Active Admin earlier, such as calling ActiveAdmin.routes in both the host and the engine.
  • The Devise views use Devise's own path helpers, so they follow router_name. With router_name, Devise looks up root_path on that route set after sign-out, so Active Admin returns its own root there. An app's after_sign_out_path_for still wins. Apps with router_name: :main_app now sign out to the admin root, as apps without it already did.
  • In engine mode, host-app helpers need main_app.. The docs say so.

Part of #9147. Request specs mount an engine at /backoffice and cover pages, sign-in and sign-out.

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.12%. Comparing base (e1dad93) to head (a58d1f5).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9154   +/-   ##
=======================================
  Coverage   99.11%   99.12%           
=======================================
  Files         139      139           
  Lines        4071     4092   +21     
=======================================
+ Hits         4035     4056   +21     
  Misses         36       36           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@senid231

senid231 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Codecov's missing line was the super branch of Helpers::Routes.method_missing. spec/unit/helpers/routes_spec.rb now covers it, and also respond_to? and default_url_options.

A review pass also found two bugs in the sign-out override, both now fixed with specs:

  • It ran ahead of ApplicationController, so an app's own after_sign_out_path_for was ignored. It now applies only when Devise's default would run.
  • A controller subclass that overrides the method and calls super skipped the engine root. The override now looks up the next method from its own module.

The docs now say that host-app route helpers need main_app. when Active Admin runs from an engine.

Route helpers always came from Rails.application.routes, so an app that
calls ActiveAdmin.routes inside an engine's routes.draw had to include
the engine's url_helpers into ActiveAdmin internals (activeadmin#4294). Devise
lookups go through router_name, so the Devise views use Devise's path
helpers and sign-out uses ActiveAdmin's root_path.

Co-Authored-By: Clanker
ActiveAdmin's sign-out override sat ahead of ApplicationController and
ignored an app's own redirect. It now applies only when Devise's default
would run.

Co-Authored-By: Clanker
A subclass that overrides after_sign_out_path_for and calls super made
method() resolve to the subclass, so the engine root was skipped. The
docs now say host-app helpers need main_app in the engine setup.

Co-Authored-By: Clanker
@senid231
senid231 force-pushed the route-helpers-engine branch from 5b5d26d to 30f4c3e Compare November 12, 2026 11:20
The spec drew routes for a temporary application and left them in place,
so a later spec that expected the admin routes could fail.

Co-Authored-By: Clanker

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant