Administrate: Sidebar fails rendering link_to with NoMethodError: undefined method `to_model' for #<Administrate::Namespace::Resource:0x0000...>

Created on 5 Apr 2018  路  4Comments  路  Source: thoughtbot/administrate

I've recently upgraded to Rails 5.1.5 and running Administrate

gem 'administrate', '~> 0.9.0', git: 'https://github.com/thoughtbot/administrate.git', branch: 'master'

My Administrate sidebar is not rendering and displays the error:

NoMethodError - undefined method `to_model' for #<Administrate::Namespace::Resource:0x00007fdd3e303338>

It occurs in the link_to function at [namespace, resource]. Should this be [namespace, @resource]??

_sidebar.html.erb

        <%= link_to(
          display_resource_name(resource),
          [namespace, resource],
          class: "sidebar__link sidebar__link--#{nav_link_state(resource)}"
        ) %>
bug install

Most helpful comment

This is just an edge case customization upgrade issue.

To reproduce one would have had previously ran rails g administrate:views:layout when app/views/admin/application/_sidebar.html.erb was referenced via app/views/layouts/admin/application.html.erb.

Of course app/views/admin/application/_navigation.html.erb has now taken the place of _sidebar.html.erb.

What I've done since and would be the proper approach is to re-run rails g administrate:views:layout and merge ones customizations with the latest Administrate layouts.

Personally, I'd just close this issue.

All 4 comments

Potentially!

I've not heard of this issue elsewhere yet, do you have a sample application I could try out and replicate with?

Replace with

```.erb
<%= link_to(
display_resource_name(resource),
[namespace, resource_index_route_key(resource)],
class: "navigation__link navigation__link--#{nav_link_state(resource)}"
) %>

```

@minimul, do you think you'd be able to open a PR with this?

I'm still not quite sure how this was happening, so if you'd be able to explain that, that'd be great too!

This is just an edge case customization upgrade issue.

To reproduce one would have had previously ran rails g administrate:views:layout when app/views/admin/application/_sidebar.html.erb was referenced via app/views/layouts/admin/application.html.erb.

Of course app/views/admin/application/_navigation.html.erb has now taken the place of _sidebar.html.erb.

What I've done since and would be the proper approach is to re-run rails g administrate:views:layout and merge ones customizations with the latest Administrate layouts.

Personally, I'd just close this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

conwayanderson picture conwayanderson  路  4Comments

MatthiasRMS picture MatthiasRMS  路  3Comments

kwerle picture kwerle  路  4Comments

migu0 picture migu0  路  3Comments

steffenix picture steffenix  路  4Comments