Intro to Rails
Ruby is a dynamic, beginner-friendly programming language, and Ruby on Rails is its flagship web framework — a full-stack toolkit that turns your Ruby skills into real, database-backed web applications.
Learn Intro to Rails in our free Ruby course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick reference.
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 of this lesson you'll understand what Rails is, the MVC pattern, convention over configuration, and how a request flows through a Rails app.
What You'll Learn in This Lesson
1️⃣ What Rails Is and How a Project Starts
Rails is a full-stack framework: routing, database access, templating, and security all come included. You scaffold an app with a few terminal commands, and Rails's convention over configuration philosophy means it wires everything together with sensible defaults — leaving you to write the parts that are unique to your app.
2️⃣ The MVC Pattern in Action
Rails organises code as Model (data and rules), View (HTML), and Controller (the coordinator). A request hits a route, the controller asks the model for data, and a view renders the result. Notice how every piece is just a Ruby class or template — everything you've already learned.
Your turn. Plan the MVC pieces for a new resource in plain Ruby. Confirm the TODO format, then run it.
Mini-Challenge: Model a Resource
A Rails model is a Ruby class with validations. Build a plain-Ruby Article with a valid? check and a summary — the same shape as a real model. Run with ruby resource.rb .
Common Errors (and the fix)
- Forgetting db:migrate — After generating a model you must run rails db:migrate to create the table.
- Naming convention mismatch — Model is singular ( Post ), table is plural ( posts ). Fighting conventions causes "uninitialized constant" errors.
- "No route matches" — You hit a URL with no matching route. Add it in config/routes.rb (often just resources :posts ).
- Skipping Ruby basics — Rails is Ruby; struggling with blocks or classes will make Rails confusing. Revisit earlier lessons.
- Wrong Ruby/Rails versions — Use a version manager and a Gemfile so your Rails version matches the tutorial you follow.
Pro Tips
- 💡 Start with a scaffold: rails generate scaffold shows a full working CRUD example to learn from.
- 💡 Use the Rails console: rails console lets you poke at models live, like irb for your app.
- 💡 Read the Guides: guides.rubyonrails.org is the canonical, beginner-friendly reference.
📋 Quick Reference — Rails
Concept
Command / Idea
New app
rails new blog
Scaffold
rails g scaffold Post ...
Migrate DB
rails db:migrate
Run server
rails server
Pattern
Model / View / Controller
Routes
resources :posts
Frequently Asked Questions
🎉 Lesson Complete!
- ✅ Rails is Ruby's flagship full-stack web framework
- ✅ Scaffold apps with rails new and generators
- ✅ Code is organised as Model / View / Controller
- ✅ ActiveRecord models map to database tables
- ✅ Convention over configuration removes boilerplate
- ✅ Next lesson: Capstone — build a real CLI app
Practice quiz
What is Ruby on Rails?
- A Ruby testing library
- A full-stack web framework written in Ruby
- A database engine
- A Ruby version manager
Answer: A full-stack web framework written in Ruby. Rails is a full-stack web framework for building database-backed web apps and APIs.
What does MVC stand for in Rails?
- Module-View-Class
- Model-View-Controller
- Method-Variable-Constant
- Map-Validate-Convert
Answer: Model-View-Controller. MVC is Model-View-Controller, the pattern Rails organises code around.
Which part of MVC talks to the database via ActiveRecord?
- The View
- The Controller
- The Model
- The Router
Answer: The Model. The Model represents data and business rules and talks to the database.
What is the role of the Controller?
- Renders HTML
- Stores data
- Receives the request, asks the Model for data, picks a View
- Defines the database schema
Answer: Receives the request, asks the Model for data, picks a View. The Controller coordinates: it handles the request and chooses what to render.
What does 'convention over configuration' mean?
- You must configure every file
- Sensible defaults wire things together so you write little setup
- Conventions are optional and ignored
- It only applies to the database
Answer: Sensible defaults wire things together so you write little setup. Following standard naming and structure lets Rails wire things up automatically.
Which command creates a brand-new Rails project?
- rails server
- rails new blog
- rails db:migrate
- rails generate
Answer: rails new blog. rails new blog scaffolds a whole project folder.
After generating a model, which command creates its database table?
- rails server
- rails console
- rails db:migrate
- rails new
Answer: rails db:migrate. rails db:migrate applies pending migrations to create the table.
Following conventions, a model named Post maps to which table?
- Post
- post
- posts
- post_table
Answer: posts. Models are singular (Post) and their tables are plural (posts).
Where are routes that map URLs to controller actions defined?
- app/models
- config/routes.rb
- app/views
- Gemfile
Answer: config/routes.rb. Routes live in config/routes.rb, often as resources :posts.
Which file type embeds Ruby in HTML using <%= %> tags?
- .rb files
- .erb view templates
- .yml files
- .json files
Answer: .erb view templates. ERB view templates (.html.erb) embed Ruby inside HTML with <%= %>.
Continue this course
- Previous: Gems & Bundler
- Next: Capstone: A CLI App