Capstone: personal blog
This capstone builds a small personal blog in Rails by hand, one step at a time. The blog has one Article model with title, body and published_at columns, plus four actions: index, show, new and create. The lessons cover the migration and a validated model, a narrowed route, the controller, index and show rendered through a shared partial, and a form that connects new and create. The views are then styled with this project's Tailwind design tokens. A closing lesson compares the result with a scaffold-generated version.
What you'll learn
- ✓Writing a migration and an Article model with a presence validation
- ✓Narrowing resources routes with only: and writing four controller actions
- ✓Handling create with a redirect on success and a 4xx status on failure
- ✓Sharing one partial between index and show, with ERB escaping
- ✓Building a form with form_with model: and showing validation errors
- ✓Styling views with Tailwind utilities generated from design tokens
Planning the blog: one model, four actions
Scaffolding: rapid prototyping ended by generating a complete Article feature in one command: migration, model, seven controller actions and six view files. Then it listed what still needed work: no validations, a permit list that trusted every column, and views with no connection to this project's…
Read the full lesson free →Curriculum
7 lessonsPlanning the blog: one model, four actions
Plans a personal blog with one Article model, three columns and four actions: index, show, new, create.
The model and migration, built by hand
Writes the CreateArticles migration and an Article model with a title validation and a published? method.
Routes and controller, tied to their courses
Narrows the articles routes to four actions and writes a controller using require and permit for parameters.
index and show, rendered with a partial
Renders index and show through one shared _article partial, with ERB escaping protecting user-submitted content.
new, create, and the form that connects them
Builds the new article form with form_with, shows validation errors and traces fields into params and create.
Styling: this project's Tailwind tokens
Styles the article partial with Tailwind utilities generated from this project's design tokens, such as text-ink.
Closing the Rails courses: from rails new to a working blog
Reviews the finished blog and compares it with a scaffold-generated version lacking validations, a reviewed permit list and styling.