A detailed walkthrough of how Rails dispatches an HTTP request to a controller action after routing has matched a route. Covers the full sequence: controller class resolution from string identifiers, fresh controller instance creation per request, params assembly from route/query/body sources, before_action callback chain execution, action method invocation, and response handling via render/redirect. Also explains why controller actions don't 'return' responses like normal Ruby methods, and provides practical debugging guidance for common controller issues like missing params or callbacks not running.
Table of contents
Start With the Right Mental ModelWhat the Router Actually Hands OffRouting Produces Identifiers. Dispatch Turns Them into ObjectsBefore the Action Runs, Rails Builds the Request ContextHow Params Are Built Before Your Action StartsYour Action Does Not Run in IsolationWhy before_action Order MattersThen Rails Invokes the Action MethodRendering vs ReturningA Simple Dispatch DiagramWhy Rails Is Designed This WayThe Final Mental ModelSort: