administrate icon indicating copy to clipboard operation
administrate copied to clipboard

Administrate::ResourceResolver always singularizes namespace.

Open timobleeker opened this issue 3 years ago • 5 comments

  • 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?

timobleeker avatar Mar 05 '21 16:03 timobleeker

I am hit by the same issue in 0.15.0, it seems only the last part of the path should be singularized.

agnessa avatar Mar 09 '21 16:03 agnessa

I agree. I can't think of a reason why namespaces should be singularized. Would someone be up for a PR?

pablobm avatar Mar 25 '21 17:03 pablobm

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 avatar Jun 28 '21 15:06 DevS1993

@DevS1993 - Yes, I'll be happy to look at a PR for this.

pablobm avatar Jul 19 '21 14:07 pablobm

@DevS1993 did you end up submitting a PR? We are running into the same issue. If not, can I submit a PR instead @pablobm?

rmachielse avatar Sep 16 '22 14:09 rmachielse