Capstone: A Rails Blog App

This is where it all comes together. You'll build a blog with posts and comments, wiring up associations, validations, forms, and authentication — every concept from the Rails track in one real application.

Learn Capstone: A Rails Blog App in our free Ruby course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…

Part of the free Ruby course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

By the end you'll have a conventional, tested Rails app you can extend and deploy, plus a quick-reference recap of the entire track.

What You'll Build in This Capstone

1️⃣ Models, Migrations, and Associations

Start by generating the project and the Post , Comment , and User models. Connect them with associations and protect the data with validations.

2️⃣ Controllers: Forms, Params, and Auth

Controllers are where forms, strong parameters, validations, and authentication meet. A before_action :require_login gates the create actions, and strong parameters keep input safe.

3️⃣ Tests and Deploy

Add tests (here with RSpec ) so you can change the app with confidence, then deploy it to a hosting platform to share with the world.

Extend the blog with tags, authorization, search, an API, or more tests — each using a skill from the track.

📋 Quick Reference — The Whole Rails Track

Practice quiz

In the blog, what associates a Post with its Comments?

  • Post belongs_to :comments
  • Post has_many :comments and Comment belongs_to :post
  • Comment has_many :posts
  • Both use has_and_belongs_to_many

Answer: Post has_many :comments and Comment belongs_to :post. A Post has_many :comments while each Comment belongs_to :post.

Which command scaffolds a brand-new blog project?

  • rails generate blog
  • rails new blog
  • rails server blog
  • bundle new blog

Answer: rails new blog. rails new blog creates the project directory.

After defining a Post model, what creates its database table?

  • rails console
  • rails db:migrate
  • rails routes
  • rails test

Answer: rails db:migrate. rails db:migrate runs the migration that builds the posts table.

Where do you whitelist the fields a Comment form may submit?

  • In the model
  • In the view
  • In the routes file
  • In a strong-parameters method via require/permit

Answer: In a strong-parameters method via require/permit. Strong parameters (params.require.permit) live in the controller.

Which validation stops a Post being saved with a blank title?

  • validates :title, presence: true
  • validates :title, length: 0
  • validates :title, unique: true
  • validates_title :present

Answer: validates :title, presence: true. presence: true rejects blank titles.

To require login before creating a post, you would use a:

  • migration
  • database index
  • before_action that checks current_user
  • flash message

Answer: before_action that checks current_user. A before_action filter enforces authentication before the action runs.

Which gem is commonly used to write tests for the blog?

  • Webpacker
  • RSpec
  • Puma
  • Sidekiq

Answer: RSpec. RSpec is a popular testing framework for Rails apps.

What does dependent: :destroy on Post has_many :comments ensure?

  • Comments are archived
  • Deleting a post deletes its comments
  • Comments cannot be deleted
  • Posts cannot be deleted

Answer: Deleting a post deletes its comments. It removes a post's comments when the post is destroyed.

What renders a list of posts in the index view?

  • A migration loop
  • Iterating @posts in the ERB template
  • render json only
  • The routes file

Answer: Iterating @posts in the ERB template. The index view iterates over @posts set by the controller.

A good final step before sharing the blog publicly is to:

  • Delete the tests
  • Deploy it to a hosting platform
  • Remove all validations
  • Disable CSRF protection

Answer: Deploy it to a hosting platform. Deploying makes the finished app available to real users.