Skip to content

Conversation

@rameerez
Copy link
Contributor

While trying to integrate madmin into my project which also uses the pricing_plans and usage_credits gems, I started getting errors like these on any madmin page, none was loading:

undefined method 'madmin_usage_credit_wallets_path'

I came across all these errors just by following the README instructions, so I thought it could be a bug, which I think it is. Fortunately, it seems like it's just a single line.

The problem was the .singularize call in here:

@route_namespace = (namespace ? namespace.name.singularize.underscore.to_sym : nil)

Which incorrectly transforms plural namespace module names. Both pricing_plans and usage_credits have multiple namespaced models, which get incorrectly converted by madmin:

  • PricingPlans → PricingPlan → :pricing_plan (should be :pricing_plans)
  • UsageCredits → UsageCredit → :usage_credit (should be :usage_credits)

This caused undefined method errors like: undefined method 'madmin_pricing_plan_assignments_path' (expected: 'madmin_pricing_plans_assignments_path')

The bug probably went undetected because Rails' built-in engines work because they're singular: ActionText, ActiveStorage, ActionMailbox don't change when singularized. Also the test suite only tests ActionText::RichTextResource, which doesn't expose the bug.

This affects all four path methods (index, new, show, edit) for any namespaced model with a plural namespace name.

After the fix all tests pass, and I also tested it manually in my app while using my other gems and now everything works fine!

Remove .singularize from route_namespace method (line 87) which was
incorrectly transforming plural namespace names:
- PricingPlans → PricingPlan
- UsageCredits → UsageCredit

This caused undefined method errors like:
  undefined method 'madmin_pricing_plan_assignments_path'
  (expected: 'madmin_pricing_plans_assignments_path')

Rails' built-in namespaces (ActionText, ActiveStorage) use singular-
sounding names that don't change when singularized, which is why this
bug went unnoticed.

All existing tests pass with this change (38 tests, 0 failures).
@excid3
Copy link
Owner

excid3 commented Dec 31, 2025

I remember adding that for some reason, but it's been so long I don't remember. I'll test this on a couple of our apps and make sure it works.

Edit: Seems fine!

@excid3 excid3 merged commit 3b56cd4 into excid3:main Dec 31, 2025
73 checks passed
@rameerez rameerez deleted the fix-plural-namespace-routing branch January 2, 2026 01:15
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.

2 participants