ruby-on-railsadministraterails-administrate

Administrate gem does not allow to view user


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?


Solution

  • 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