Ruby on Rails — Full-Stack Web Framework That Started It All
Ruby on Rails is a full-stack web framework optimized for programmer happiness. Convention over configuration, MVC architecture, ActiveRecord ORM, migrations, and scaffolding. Created by DHH in 2004 and still powering GitHub, Shopify, Basecamp, and Airbnb.
What it is
Ruby on Rails is a full-stack web framework built on the Ruby programming language. Created by DHH in 2004, it popularized conventions like MVC architecture, convention over configuration, and database migrations. Rails includes ActiveRecord ORM, Action Cable for WebSockets, Active Storage for file uploads, and built-in testing frameworks.
Rails is designed for developers who value productivity and convention-driven development, enabling rapid prototyping and production deployment of web applications.
How it saves time or tokens
Rails generators and scaffolding produce working CRUD interfaces in seconds. The convention-over-configuration philosophy means you write less configuration code: database tables map to models automatically, routes follow RESTful conventions, and views follow naming patterns. A feature that requires extensive boilerplate in other frameworks is often a one-liner in Rails. Migrations make database schema changes trackable and reversible.
How to use
- Install Rails and create a new project:
gem install rails
rails new myapp --database=postgresql
cd myapp
rails db:create
rails server
# Visit http://localhost:3000
- Scaffold a resource:
rails generate scaffold Post title:string body:text published:boolean
rails db:migrate
- Visit
http://localhost:3000/postsfor a complete CRUD interface with forms, validation, and JSON API.
Example
A complete API endpoint with validation and authentication:
# app/models/post.rb
class Post < ApplicationRecord
belongs_to :user
validates :title, presence: true, length: { maximum: 100 }
validates :body, presence: true
scope :published, -> { where(published: true) }
end
# app/controllers/api/posts_controller.rb
class Api::PostsController < ApplicationController
before_action :authenticate_user!
def index
posts = Post.published.order(created_at: :desc).limit(20)
render json: posts
end
def create
post = current_user.posts.build(post_params)
if post.save
render json: post, status: :created
else
render json: { errors: post.errors }, status: :unprocessable_entity
end
end
private
def post_params
params.require(:post).permit(:title, :body, :published)
end
end
Related on TokRepo
- Coding tools — Browse development frameworks and tools
- Featured tools — Discover popular tools on TokRepo
Common pitfalls
- N+1 query problems. ActiveRecord makes it easy to trigger N+1 queries with associations. Use
includes(:association)or tools like Bullet to detect and fix them. - Not running migrations in production before deploying code. The deploy process should run
rails db:migratebefore restarting the application to avoid schema mismatches. - Over-relying on scaffolding for production code. Scaffolding is a starting point, not production-ready code. Customize the generated controllers and views for your specific requirements.
- Starting with an overly complex configuration instead of defaults. Begin with the minimal setup, verify it works, then customize incrementally. This approach catches configuration errors early and keeps troubleshooting straightforward.
Frequently Asked Questions
Yes. Rails powers major applications like Shopify, GitHub, Basecamp, and Hey. The framework continues to evolve with features like Hotwire for real-time UIs without JavaScript frameworks. Its productivity advantages remain compelling for many use cases.
Rails includes Active Job, a unified interface for background job processing. It works with backends like Sidekiq, Resque, and Solid Queue (Rails 8 default). Jobs handle tasks like email sending, data processing, and API calls.
Yes. Use rails new myapp --api to create an API-only Rails application. This skips view-related middleware and generators, producing a lean JSON API framework.
Hotwire (HTML Over The Wire) is Rails' approach to building real-time, reactive web applications without writing custom JavaScript. It includes Turbo (page navigation, frames, streams) and Stimulus (lightweight JS controllers).
Rails can be deployed with Kamal (Docker-based), Heroku, Render, or traditional server setups with Puma as the app server and Nginx as the reverse proxy. Rails 8 introduced Kamal as the default deployment tool.
Citations (3)
- Rails GitHub— Ruby on Rails is a full-stack web framework
- Rails Guides— Rails documentation and guides
- Rails Doctrine— Convention over configuration philosophy
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.