Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix custom namespace routing.#8876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
craigmcnamara wants to merge6 commits intoactiveadmin:master
base:master
Choose a base branch
Loading
frommes-amis:fix-namespace-customizations

Conversation

@craigmcnamara
Copy link
Contributor

ActiveAdmin 4.0'sisolate_namespace caused route helpers to fail for custom namespaces (e.g.,:active_admin instead of:admin) becauseurl_for looked in the engine's
routes instead of the main app's routes. This adds a proxy module that overridesurl_for to route hash options throughRails.application.routes, and updates the base
controller to merge request context for relative URL generation. The polymorphic route helpers also default toonly_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.
@tagliala
Copy link
Contributor

tagliala commentedDec 5, 2025
edited
Loading

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 overridesurl_for to route hash options through Rails.application.routes

At a glance, overridingurl_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 implementedisolate_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 usemain_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 thisactiveadmin-v4-custom-namespace-bug-report.md file referenced here?

Copy link
ContributorAuthor

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
ContributorAuthor

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 freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@taglialataglialatagliala left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

3 participants

@craigmcnamara@tagliala@javierjulio

[8]ページ先頭

©2009-2025 Movatter.jp