Controller Code Is Configuration
Explore the unique role of Rails controllers as a configuration language that handles HTTP requests and responses. Learn to keep controller code minimal by delegating business logic elsewhere, reducing complexity and improving sustainability in your Rails applications.
We'll cover the following...
We'll cover the following...
Unique role of controllers in Rails
If we want to respond to an HTTP request in a Rails application, we need to use a controller. That’s why they exist. In this sense, only a controller can receive an HTTP request, trigger business logic based on it, and then send a response, be that rendering a view or redirecting to another path.
There are four issues around controllers that can cause sustainability problems:
- Controller code is structured unlike any other code, in any system we’ve ever seen. Controller code can seem quite alien; it isn’t