Skip to content

Set engine layout on ApplicationController#72

Open
fcatuhe wants to merge 1 commit intofractaledmind:mainfrom
fcatuhe:fix/set-engine-layout-on-application-controller
Open

Set engine layout on ApplicationController#72
fcatuhe wants to merge 1 commit intofractaledmind:mainfrom
fcatuhe:fix/set-engine-layout-on-application-controller

Conversation

@fcatuhe
Copy link
Contributor

@fcatuhe fcatuhe commented Feb 25, 2026

Problem

When base_controller_class is configured to a controller that declares its own layout (e.g. layout "admin"), Litestream::ApplicationController inherits that layout. Since the host app's layout uses route helpers that aren't available inside a mounted engine, this causes a NameError:

NameError: undefined local variable or method 'some_host_app_path'
  from app/views/layouts/admin.html.erb:1

Root cause

Litestream::ApplicationController doesn't declare its own layout. The litestream/application layout file exists, but without an explicit layout declaration on the controller, Rails resolves the layout from the parent class.

Fix

Add layout "litestream/application" to Litestream::ApplicationController. This matches what other Rails engine dashboards do:

  • mission_control-jobs: layout "mission_control/jobs/application"
  • audits1984: layout "audits1984/application"
  • blazer: layout "blazer/application"

Tests

  • Unit test: asserts the controller's layout is litestream/application regardless of the base controller's layout
  • Integration test: asserts the rendered page uses the engine's <title>Litestream</title>, not the host app's
  • The dummy app's MyApplicationController now sets layout "application" to exercise this scenario

Without an explicit layout declaration, Litestream::ApplicationController
inherits the layout from its base_controller_class. When the base controller
declares its own layout (e.g. `layout "admin"`), Litestream renders
inside the host app's layout, which breaks because main app route helpers
are not available inside mounted engine views (NameError).

This matches what other Rails engine dashboards do:
- mission_control-jobs: `layout "mission_control/jobs/application"`
- audits1984: `layout "audits1984/application"`
- blazer: `layout "blazer/application"`

The litestream/application layout already exists — it just was never
declared on the controller.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant