Skip to content

Conversation

@craigmcnamara
Copy link
Contributor

ActiveAdmin 4.0's isolate_namespace caused route helpers to fail for custom namespaces (e.g., :active_admin instead of :admin) because url_for looked in the engine's
routes instead of the main app's routes. This adds a proxy module that overrides url_for to route hash options through Rails.application.routes, and updates the base
controller to merge request context for relative URL generation. The polymorphic route helpers also default to only_path: true to avoid host resolution errors.

Fixes #8279

  ActiveAdmin 4.0's `isolate_namespace` caused route helpers to fail for custom namespaces (e.g., `:active_admin` instead of `:admin`) because `url_for` looked in the engine's
  routes instead of the main app's routes. This adds a proxy module that overrides `url_for` to route hash options through `Rails.application.routes`, and updates the base
  controller to merge request context for relative URL generation. The polymorphic route helpers also default to `only_path: true` to avoid host resolution errors.
Rubocop caught me here.
@tagliala
Copy link
Contributor

tagliala commented Dec 5, 2025

Hi, thanks for this PR.

I'm not familiar with the underlying issue and I couldn't reproduce #8279. There isn’t a failing test demonstrating the bug in this PR.

Could you add a minimal failing test that reproduces the problem and show why it happens?

This adds a proxy module that overrides url_for to route hash options through Rails.application.routes

At a glance, overriding url_for (plus the many condition branches to make it work) feels like a heavy-handed solution. Before accepting a global override of such a core helper, I'd like to understand the root cause better and see whether a smaller, more targeted change could fix it. Or, maybe this behavior should be documented as a current limitation.

@javierjulio and @mgrunberg any thought?

@javierjulio
Copy link
Member

@craigmcnamara thank you for attempting to address this. I noticed the test suite is failing for the comments resource still.

@tagliala in general I don't know much about engines. The reason for why it fails makes sense. I implemented isolate_namespace because it's what the Rails guide suggests and to help address code reloading issues. I anticipated that there would be some potential issues here. I could only find that it required me to use main_app proxy in Devise templates but that was it since I rely on the default admin namespace.


RSpec.describe "Custom Namespace Routes", type: :request do
# Test that custom namespaces (other than :admin) can access route helpers
# This reproduces the bug from: activeadmin-v4-custom-namespace-bug-report.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this activeadmin-v4-custom-namespace-bug-report.md file referenced here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, that was a bug report from my app. I need to clean this up a bit.

@craigmcnamara
Copy link
Contributor Author

Could you add a minimal failing test that reproduces the problem and show why it happens?

The reproduction is in spec/requests/custom_namespace_routes_spec.rb

If you remove the overrides those fail. My production app successfully loads ActiveAdmin with the patches and fails exactly like the bug report without them.

My understanding is when routing params are omitted the routes helper infers them from the current request in the controller or view context. It seems the way the routes are used in ActiveAdmin, the helper doesn't always have the request context and that info isn't picked up.

This isn't my first foray into ActiveAdmin, I wrote the patch that allows unlimited sized CSV downloads by implementing a streaming response back in the v1 days.

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.

No access to routes helpers from ActiveAdmin views [v4.0.0.beta5]

3 participants