Documentation Index
Fetch the complete documentation index at: https://mintlify.com/crashtech/torque-admin/llms.txt
Use this file to discover all available pages before exploring further.
DashboardController is a lightweight Rails Concern that turns any controller into the home page of your Torque Admin application. It handles template path registration, optional async streaming, and integration with the routing DSL that declares dashboard routes and partials. In most apps, a dashboard controller is either generated automatically by the router or created manually as a thin class that includes this concern.
Including the Concern
DashboardController automatically:
- Registers three template search paths (see Template Resolution below).
- Enrols the
:indexaction for async streaming whenconfig.stream_actionsistrue. - Mixes in
StreamControllerfor Turbo-compatible async rendering.
Streaming Setup
admin_application.config.stream_actions is enabled, the dashboard :index action automatically uses ActionController::Live for streaming. This allows panels, stats blocks, and other dashboard widgets to be rendered and flushed to the browser incrementally, improving perceived performance on dashboards with multiple slow data sources.
Template Resolution
Three template paths are appended when the concern is included, checked in priority order (highest first):| Priority | Path | Purpose |
|---|---|---|
| 1 (highest) | app/templates/<admin_name>/dashboard/ | App-level overrides scoped to a specific admin namespace |
| 2 | app/templates/dashboard/ | App-level overrides shared across all admin namespaces |
| 3 (lowest) | <gem>/app/templates/dashboard/ | Gem-provided built-in defaults |
Declaring Dashboard Routes
Dashboard routes are declared inside theadmin block in config/routes.rb using the dashboard mapper method provided by Torque::Admin::Mapper::Dashboards.
Basic dashboard route
GET / route dispatched to DashboardController#index and creates named route helpers dashboard_path and root_path within the admin engine.
Dashboard with partials
Partials are individual GET routes nested under the dashboard path. They are useful for streaming individual panels from a Turbo Frame:DashboardController, so you can define those actions (and their corresponding templates) independently.
Dashboard scoped to a path
Pass a path prefix as the first argument to nest the dashboard under a sub-path:If no
dashboard route has been declared by the time routes are finalised, Torque Admin automatically adds one via finalize_routes!. Internally, Application#finalize_routes! calls auto_dashboard_route, which runs dashboard_root through a new Mapper instance. dashboard_root only registers the dashboard route itself when no dashboard named route already exists, but it always registers a root alias (mapping e.g. root_path to the dashboard route) regardless of whether the dashboard was added by this call or was declared earlier. This ensures every admin application always has a working home page and a root path helper.Complete Routing + Controller Example
The following example shows a custom dashboard with streaming enabled, two stat partials, and a reference to a resource widget rendered inline in the index template.Routes
Controller
Index template (app/templates/admin/dashboard/index.html.erb)
Using Resource Widgets in Dashboard Templates
Resources can declare widgets via thewidgets mapper helper, which registers dedicated GET routes and marks the action as a widget type in the RESOURCE metadata. Those widgets can then be referenced from dashboard templates, since WidgetsController (included through ResourceController) exposes the underlying data helpers.
:summary and :engagement_chart actions on PostsController are now discoverable as widgets and can be rendered inside dashboard frames or other admin views, keeping dashboard data fetching co-located with the resource that owns the data.