administrate
administrate copied to clipboard
Administrate::ResourceResolver always singularizes namespace.
-
What were you trying to do? Make a dashboard for a namespaced resource:
Users::Preference
-
What did you end up with (logs, or, even better, example apps are great!)?
uninitialized constant User::PreferenceDashboard
-
What versions are you running?
- Rails 6.0.3
- administrate 0.13.0
From reading the source of the Administrate::ResourceResolver
, it's always going to singularize the namespace:
def controller_path_parts
controller_path.split("/")[1..-1].map(&:singularize)
end
I don't understand why it would want to signularize the namespace part of the controller path. To my knowledge it is not possible to have Foo::Bar
in foos/bar.rb
. Would it not make more sense to just singularize the last part of the controller path?
Am I missing something, or is this a bug in administrate?
I am hit by the same issue in 0.15.0, it seems only the last part of the path should be singularized.
I agree. I can't think of a reason why namespaces should be singularized. Would someone be up for a PR?
One way to monkey patch this for an immediate fix, would be to add an initializer (with any appropriately named file) and add this snippet :
Administrate::ResourceResolver.module_eval do
def controller_path_parts
path_parts = controller_path.split("/")[1..-1].map(&:singularize)
# How you want to handle this.
end
end
I didn't find any open PR's fixing this issue, @pablobm can i submit a PR?
@DevS1993 - Yes, I'll be happy to look at a PR for this.
@DevS1993 did you end up submitting a PR? We are running into the same issue. If not, can I submit a PR instead @pablobm?