2

A Rails 6.0 uses gem administrate. Users flagged as admin access the pages properly.

The user index is displayed and, for example, the edit page is accessible:

/admin/users/2579/edit

but calling the same object's show page returns an error

undefined method `admin_role_path'

pointing to line 59 of app/views/admin/application/_collection.html.erb which is automaatically generated by the administrate gem

<%= %(tabindex=0 role=link data-url=#{polymorphic_path([namespace, resource])}) %>

Trace of template inclusion: #<ActionView::Template /.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/administrate-0.14.0/app/views/fields/has_many/_show.html.erb locals=["field", "page"]>, #<ActionView::Template app/views/admin/application/show.html.erb locals=["page"]>

I remove all the code and replaced it with a simple <%= ressource %>, toggling the equals sign to a hash. Three join (of has_many) classes have an ActiveRecord_AssociationRelation which undestandably invokes the collection form. <%= ressource.inspect %> allows to view the details of each relation.

Still the mechanics of the error generation are opaque to me as the aformentioned path is not found in the repository.

What is the source of the problem and how can it be managed?

Jerome
  • 5,583
  • 3
  • 33
  • 76

1 Answers1

1

I think you are leaving out some important information. Am I right to think that your User model has_many :roles?

You are in the "show" page, and Administrate is trying to render a "collection". It looks like it's trying to render the roles of the user and that's what's failing.

The error says undefined method 'admin_role_path'. That suggests to me that the route /admin/roles/:id doesn't exist. Is that the case?

I just had a look and reproduced the problem myself. It's a bug in Administrate. We should be checking whether there is a "show" route for the associated model. In this case there isn't, and it fails.

A workaround would be to provide a route for roles: resources :roles. The proper solution would be to fix the bug.

I have just filed an issue in the repo for this: https://github.com/thoughtbot/administrate/issues/1861

pablobm
  • 2,026
  • 2
  • 20
  • 30
  • You are correct, but the situation is a tad more complex. The User class has a boolean attribute `admin` for being able to handle administrate; it is meant as a boolean because this is an open/shut case. However, you are correct, there is a Role class that `has_many :roles, through: :userroles`. I did comment out in the `namespace :admin` block `# resources :roles` to avoid having it listed (visual encumbrance) in the admin column. – Jerome Jan 08 '21 at 11:22