---
title: Keep controllers thin
impact: HIGH
impactDescription: Maintain single responsibility and improve testability.
tags: rails, architecture, controllers, mvc
---

## Keep controllers thin

Maintain single responsibility and improve testability. Controllers should only handle HTTP requests and responses (parsing params, calling logic, redirecting/rendering). Extract complex business logic into service objects, models, or concerns.

**Incorrect:**

```ruby
class OrdersController < ApplicationController
  def create
    @order = Order.new(order_params)
    # Complex business logic in controller
    if @order.save
      Inventory.decrease(@order.product_id)
      EmailService.send_confirmation(@order.user)
      redirect_to @order
    else
      render :new
    end
  end
end
```

**Correct:**

```ruby
class OrdersController < ApplicationController
  def create
    @order = Order.new(order_params)
    if OrderCreationService.call(@order)
      redirect_to @order
    else
      render :new
    end
  end
end
```

**Tools:** RuboCop (`Metrics/MethodLength`)
