I’m not sure if this suggested feature was posted before, however, but here is the idea:
**
Context:** Currently, when a developer hits a ActionDispatch::MissingController (uninitialized constant) error, the workflow requires switching contexts:
-
Read the error in the browser.
-
Switch to the terminal.
-
Type
bin/rails generate controller ... -
Switch back to the browser and refresh.
The Proposal: I propose adding a “Generate Missing Controller” button directly to rescue template. When clicked, this button would trigger the Rails controller generator via a development-only internal route or will create a new action inside an existing controller.
How it works:
-
Detection: The
DebugExceptionsmiddleware identifies theMissingControllerexception. -
Interaction: A button appears in the UI that sends a POST request to
/__rails/create_controller. -
Action: The middleware invokes
Rails::Generators.invoke("controller", [name]). -
Experience: The page auto-reloads, and the developer can immediately start working on their code without leaving the browser.
Benefits:
-
Reduced Friction: Especially helpful for beginners who are still learning the naming conventions of Rails.
-
Speed: Faster “Red-to-Green” cycle during the initial scaffolding phase of a project.
-
Precedent: This follows the spirit of
ActiveRecord::PendingMigrationError, which already provides a “Run Pending Migrations” button in the browser.
Security: This would be strictly limited to the development environment and protected within the DebugExceptions middleware, ensuring no impact on production security or performance.
Previous similar behavior: Rails already does something similar for database migrations.