Chapter 8. Handling Requests with ActionController

Rails is the most well thought-out web development framework I've ever used. And that's in a decade of doing web applications for a living. I've built my own frameworks, helped develop the Servlet API, and have created more than a few web servers from scratch. Nobody has done it like this before.

—James Duncan Davidson, Creator of Tomcat and Ant

ActionController is a key module used by Rails to handle incoming requests by mapping them with, and handing over control to, specific public instance methods known as actions. ActionController works closely with ActionView to formulate a proper response for each request, and together they form a powerful framework known as ActionPack.

The process of going from an incoming request to a complete response that's sent back to the user's browser can be divided into three logical steps: routing the request to determine which action should handle it; executing the code of the action; and finally rendering a template in the view layer. The first two steps are managed by ActionController and, together with testing, are the main subject of this chapter.

When a request comes in, ActionController uses a routing component that looks up the routes defined for the project to determine which controller and action should handle the incoming request. As soon as the controller has been identified, its class is instantiated. The details of the incoming request and a new response object are then passed to ...

Get Ruby on Rails® for Microsoft Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.