Scaffolding: rapid prototyping
This course runs the Rails scaffold generator for an Article resource in a disposable app and reads every file it produces. It covers the terminal output and the order of the internal generators. It then examines the generated migration, the empty model and the controller with all seven RESTful actions, including before_action and params.expect. The generated views and partials show what generic code looks like. The last lessons cover rails destroy, missing validations, the permit list and when scaffolding fits prototypes or internal tools.
What you'll learn
- ✓Reading the scaffold generator's terminal output and the order of its internal generators
- ✓How the generated migration and empty model map to column names and types
- ✓The seven generated controller actions, before_action and params.expect
- ✓How generated partials, shorthand render and the shared form_with form work
- ✓Undoing a scaffold with rails destroy and rolling back its migration
- ✓Gaps in generated code: validations, permitted params, styling and namespaced controllers
Scaffold: what one command generates
Getting Article from nothing to a working feature took eight courses. There was a migration (ActiveRecord: migrations), a model with a validation (ActiveRecord: model introduction), and a controller with index, show, new and create (ActionController: actions). Then came a safe article_params…
Read the full lesson free →Curriculum
7 lessonsScaffold: what one command generates
Shows the files one scaffold command generates and why the generated feature is a starting point.
Running it in a scratch app
Runs the scaffold command in a disposable Rails app and reads the order of its internal generators.
The migration and model, already written
Reads the generated migration and the empty Article model, and notes that no validation rules are added.
The controller: all seven actions, at once
Walks through the seven generated controller actions, the before_action lookup and params.expect in article_params.
The views: functional, not finished
Examines the generated partials, the shorthand render, the shared form_with form and the literal inline styles.
When scaffolding helps, and when it doesn't
Covers rails destroy, the uses that suit scaffolding and the gaps the generated code leaves.
Putting it together: one command, eight courses
Traces each generated file to the Rails topic it matches and restates the trade-offs of scaffolding.