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.
ResourceController is the top-level Rails Concern you include in any resource-backed admin controller. It assembles every specialised sub-concern — streaming, collection management, member lookup, index/show/form rendering, batch operations, custom actions, and widgets — into a single, coherent CRUD interface. Including it gives your controller the full set of Torque Admin capabilities with one line of code.
Including the Concern
The constants
RESOURCE (a Torque::Admin::Resource instance) and RESOURCE_PARAM (the URL param key, e.g. :id) are not set manually. The router’s resources (or resource) mapper calls app.setup_controller behind the scenes, which hooks into Rails autoloading and injects both constants into your controller class when it is first loaded. You never need to define them yourself.Included Concerns
ResourceController pulls in the following concerns in order. Each one is documented in its own section.
| Order | Concern | Responsibility |
|---|---|---|
| 1 | StreamController | Async / streaming action support via ActionController::Live |
| 2 | CollectionController | Scoped collection loading with filter, scope, sort, and pagination pipeline |
| 3 | MemberController | Single-record lookup; exposes resource / member helpers to views |
| 4 | IndexController | Index page element coordination (planned — currently a stub) |
| 5 | ShowController | Show page element coordination (planned — currently a stub) |
| 6 | FormController | Form record initialisation and form_element setup |
| 7 | BatchController | Batch-action support between index and processing actions (planned — currently a stub) |
| 8 | ActionsController | Default handlers for router-generated actions (e.g. search) (planned — currently a stub) |
| 9 | WidgetsController | Widget data helpers for index and dashboard pages (planned — currently a stub) |
IndexController, ShowController, BatchController, ActionsController, and WidgetsController are included by ResourceController but their implementations are still in progress. Each module file contains only a TODO comment describing the planned behaviour. They are safe to include — they add no methods yet — but any behaviour they will provide in the future is not yet available.Template Path Resolution
WhenResourceController is included, three template paths are appended (in priority order, highest first):
Streaming Setup
config.stream_actions is true, the :index and :show actions are automatically enrolled for async streaming via ActionController::Live. You can add further actions with stream_from_actions directly in your controller.
Element Aliases
Two element aliases are registered at include time:| Alias | Resolves to |
|---|---|
primary_form | new_form, create_form, edit_form, update_form |
search_form | index_form |
primary_form element in your UI DSL and have it used across all four CRUD form actions automatically.
Before-Action Hook
eager_load_resource runs. It inspects params for RESOURCE_PARAM:
- If present — calls
resource(i.e.MemberController#resource) to load and memoize the individual record. - If absent — calls
scoped_resourceto load and memoize the base collection scope.
Protected Methods
scoped_resource
Returns the appropriate ActiveRecord scope for the current request.
- When the route has no nesting annotation, delegates to
default_scoped_resource, which returnsRESOURCE.resource_class.default_scoped. - When the route has a nesting annotation (i.e. the resource is nested inside another), delegates to
chained_scoped_resourceto resolve the correct nested scope.
default_scoped_resource
chained_scoped_resource(chain)
{ param_key => controller_name } pairs) by calling find_chain_parent!, then uses nested_scope_from to scope through the found parent record.
find_chain_parent!(chain, values: params, assign: true)
Iterates over each entry in the nesting chain. For every entry it:
- Finds (or initialises) the corresponding side controller via
initialized_side_controllers. - If a previous parent exists, scopes through it first.
- Calls
find_member!on the side controller using the appropriate URL parameter. - Optionally memoises the found record into its named instance variable.
/departments/:department_id/teams/:team_id/members) to be resolved automatically.
nested_scope_from(foreign_member, reflection: nil, macro: :belongs_to)
belongs_to association on RESOURCE.resource_class that matches the type of foreign_member, then calls that association method on the parent record to return the nested scope. Raises a descriptive error if no matching reflection is found.
BaseController Utilities
BaseController (included transitively) provides shared infrastructure used throughout all sub-concerns:
| Helper | Description |
|---|---|
admin_application | The Torque::Admin::Application instance for this admin |
admin_application_config | Shortcut to admin_application.config |
admin_controller_name | Underscored controller name, relative to the admin namespace |
ui_framework | The UI framework name from the configured theme builder |
route_annotations | Hash of annotations attached to the current route by the mapper |
route_annotation(key) | Single annotation value lookup |
initialized_side_controllers | Lazy hash of sibling controller instances sharing this request/response pair |
Elements::Frame, Elements::Templates, Elements::Controller) are also mixed in, enabling the frame, append_template_path, and element fetch APIs.
SettingsController
SettingsController is included by BaseController and provides a declarative way to attach per-action settings:
settings_for_actions class attribute and are looked up by the current action_name by default. You can pass an explicit action: keyword to read settings for a different action.
Complete Example
The example below shows a minimal but completePostsController using ResourceController. It overrides default_scoped_resource for tenant scoping and uses action_settings to declare index columns and default per-page.
