Ruby on Rails Overview
47.1 What is Rails?
A full-stack web framework (David Heinemeier Hansson, 2004). Principles: Convention over Configuration, Don't Repeat Yourself, "the one-person framework."
Rails 8 (2024) highlights: Solid Queue/Cache/Cable (database-backed infrastructure), Kamal 2 deployment, Thruster, a built-in authentication generator, Propshaft, SQLite production-ready, plus Hotwire (Turbo + Stimulus) for modern UIs without heavy JavaScript.
47.2 Core Workflow
gem install rails
rails new blog --database=postgresql
cd blog
bin/rails generate scaffold Post title:string body:text published:boolean
bin/rails db:migrate
bin/rails server # http://localhost:3000/posts
bin/rails console
bin/rails routes
bin/rails test47.3 Architecture
Models (Active Record) Data, validations, associations, business logic Views (Action View)
ERB templates, partials, helpers, Turbo Frames/Streams Controllers (Action Controller)
Request handling, params, filters, responses resources:posts, nested routes, constraints Active Job Background jobs (Solid Queue, Sidekiq) Action Mailer / Mailbox Email sending/receiving Action Cable Active Storage File uploads (S3, GCS, Azure) Action Text Active Support
Core extensions (3.days.ago, blank?, present?, inflections)
Learning Rails deserves its own course. Key topics: MVC, REST, migrations, associations, validations, strong parameters, authentication/authorization (Pundit, CanCanCan), testing (Minitest/RSpec + system tests), Hotwire, API mode, caching, jobs, deployment (Kamal), security (CSRF, SQL injection protection, Brakeman).
class PostsController < ApplicationController
before_action :set_post, only: %i[show edit update destroy]
def index = @posts = Post.published.order(created_at: :desc).page(params[:page])
def create
@post = Post.new(post_params)
if @post.save
redirect_to @post, notice: "Post created."
else
render :new, status: :unprocessable_entity
end
end
private
def set_post = @post = Post.find(params[:id])
def post_params = params.expect(post: [:title, :body, :published]) # Rails 8 (params.require(:post).permit(...) earlier)
end