Rails MVC overview
This course explains Model-View-Controller as a design pattern, starting with its origin at Xerox PARC in 1979 and its use in Smalltalk-80. It covers what each role owns: the Model holds data and business rules, the View handles presentation, and the Controller coordinates between them. Lessons show why separation of concerns helps testing and change, discuss fat models versus service objects, and describe fat controllers, anemic models and duplicated logic. A small publish feature ties the three layers together.
What you'll learn
- ✓The origin of MVC and the three roles it defines
- ✓Which code belongs in the Model, the View and the Controller
- ✓Why a re-rendered form needs status: :unprocessable_content with Turbo
- ✓The trade-off between fat models and service objects
- ✓How separation of concerns helps testing and lets one Model back several Views
- ✓How to spot fat controllers, anemic models and duplicated logic
What is MVC?
The web: request-response walked through the full path a Rails request takes: Puma, middleware, router, controller, model, view. This course looks at something narrower: MVC itself, as a design pattern rather than Rails plumbing.
Read the full lesson free →Curriculum
7 lessonsWhat is MVC?
Traces MVC to Xerox PARC in 1979 and defines the separate jobs of Model, View and Controller.
The model owns data and rules
Shows that validations and derived facts like published? belong in the Model, while generating HTML does not.
The view owns presentation, only
Explains that Views display prepared data with if and each, without recalculating business rules in templates.
The controller is a traffic cop
Covers Controllers as coordinators, Turbo's need for a 4xx status, and fat models versus service objects.
Why separation of concerns matters
Shows how separation of concerns allows isolated Model tests, independent layer changes and several Views per Model.
Common MVC mistakes
Describes the fat controller, the anemic model and one business fact duplicated across several layers.
Putting it together: reading a feature end to end
Reads a publish feature across Model, Controller and View, including why update! is used instead of update.