Created by: frm
- Fixes #481 (closed) and #507 (closed)
- Possibly replaces #514. This fix assumes the controller will use the administrate layout and stylings. A complete replacement would be to implement route blacklisting.
Why:
- Currently administrate assumes there is a model for routes within the admin namespace. The navigation partial and application helper use the associated model to get the resource name.
- The workaround for this is overriding the navigation partial to blacklist certain routes from appearing.
- This workaround means users need to use custom styling and don’t get the default administrate layout styling.
- A consequence of the navigation partial is that administrate assumes
there is an
index
route, since it tries to place all the resources in the navigation sidebar. It might not be necessarily true that an administrated model might have an index route. - A proposed solution might be the one suggested by @archonic in https://github.com/thoughtbot/administrate/issues/507#issuecomment-311232431
This change addresses the need by:
- Changing the namespace to return only routes with the index route (including custom controllers)
- Updating the navigation partial and application helper to get the resource name from the dashboard.
- Adding
Administrate::CustomDashboard
with defaults for the resource name. Users can now add custom controllers without related models:
# app/dashboards/stat_dashboard.rb
require "administrate/custom_dashboard"
class StatDashboard < Administrate::CustomDashboard
resource "Stats"
end
# config/router.rb
namespace :admin do
# ...
resources :stats, only: [:index]
end