MVC Request Flow
How a Request Flows Through Rails
Browser Request
↓
Router → routes.rb maps URL to controller#action
↓
Controller → Handles request, calls models
↓
Model → ActiveRecord: DB queries, validations, logic
↓
Controller → Sets instance variables for view
↓
View → ERB template renders HTML
↓
Response sent to browser
Creating a New Rails App
rails new — Project Generation
# Rails 8 with modern defaults
rails new myapp # SQLite + Propshaft + Puma
rails new myapp -d postgresql # PostgreSQL
rails new myapp --api # API-only (no views)
rails new myapp -T # Skip Minitest (use RSpec)
rails new myapp --css tailwind # Tailwind CSS
Routing
config/routes.rb — URL Mapping
# config/routes.rb
Rails.application.routes.draw do
root "pages#home"
# RESTful resources
resources :users do
resources :posts, only: [:index, :create]
end
# Custom routes
get "about", to: "pages#about"
post "login", to: "sessions#create"
# Namespace
namespace :api do
namespace :v1 do
resources :articles, only: [:index, :show]
end
end
# Health check (Rails 8)
get "up", to: "rails/health#show", as: :rails_health_check
end
ActiveRecord Essentials
Models — Associations, Validations, Scopes
class User < ApplicationRecord
# Associations
has_many :posts, dependent: :destroy
has_one :profile
belongs_to :team
has_many :comments, through: :posts
# Validations
validates :email, presence: true, uniqueness: true
validates :name, length: { minimum: 2, maximum: 50 }
# Scopes
scope :active, -> { where(active: true) }
scope :recent, -> { order(created_at: :desc).limit(10) }
scope :admins, -> { where(role: "admin") }
# Callbacks
before_save :normalize_email
private
def normalize_email
self.email = email.downcase.strip
end
end
# Queries
User.where(active: true).order(:name)
User.find_by(email: "matz@ruby.org")
User.includes(:posts).where(posts: { published: true })
User.active.recent.count
Rails Commands
| Command |
Purpose |
| rails new APP |
Create new app |
| rails server / rails s |
Start dev server |
| rails console / rails c |
Interactive console |
| rails generate model NAME |
Generate model + migration |
| rails generate controller NAME |
Generate controller |
| rails generate migration NAME |
Generate migration |
| rails db:migrate |
Run pending migrations |
| rails db:rollback |
Undo last migration |
| rails db:seed |
Run db/seeds.rb |
| rails routes |
Show all routes |
| rails credentials:edit |
Edit encrypted credentials |
| rails generate authentication |
Generate auth system (Rails 8) |
Rails 8 Features
Kamal 2
Deploy to any VPS with zero-downtime deploys. Built-in to Rails 8. No PaaS required.
Solid Queue
Database-backed job backend. Replaces Redis + Sidekiq for most apps.
Solid Cache
Database-backed cache store. One less infrastructure dependency.
Solid Cable
Database-backed Action Cable adapter. WebSockets without Redis.
Propshaft
Modern asset pipeline. Replaces Sprockets. Fingerprinting + load paths only.
Thruster
HTTP/2 proxy in front of Puma. Asset compression + caching built-in.
Authentication Generator
rails generate authentication creates a complete auth system.
Kamal Proxy
Zero-downtime deploy proxy. Handles SSL, routing, health checks.
No PaaS Required
Rails 8’s motto: deploy to a $5 VPS and scale from there.
Hotwire Stack
Turbo Drive
Intercepts link clicks and form submissions, swaps <body> content via AJAX. No full page reloads. Zero JavaScript required.
Turbo Frames
Decompose pages into independently-updating frames. Click a link inside a frame, only that frame updates.
Turbo Streams
Deliver partial page updates over WebSocket or HTTP. Append, prepend, replace, remove DOM elements from the server.
Stimulus
Modest JavaScript framework. Attach behavior to HTML with data-controller, data-action, data-target attributes.
Convention over Configuration — Rails makes decisions for you so you can focus on building your product. Default project structure, naming conventions, and sensible defaults mean less bikeshedding and more shipping.
Rails: Rails 8’s “one person framework” vision means a solo developer can build, deploy, and operate a production web application. Kamal deploys to any VPS, Solid Queue/Cache/Cable eliminate Redis, and Thruster eliminates nginx.
↑ Back to Top