Ruby on Rails

Also known as: Rails

On this page 7

Ruby on Rails, usually called Rails, is an open-source server-side web framework written in the Ruby language that structures applications around the model-view-controller (MVC) pattern. In web architecture, it is the classic example of a full-stack, batteries-included framework: one codebase handles routing, database access, HTML rendering, background jobs, email and real-time updates.

Rails was extracted from a project-management product by David Heinemeier Hansson and released publicly in 2004. Its principles of convention over configuration and do not repeat yourself (DRY) strongly influenced later frameworks such as Django, Laravel and Phoenix.

How Ruby on Rails structures an application

A Rails application processes each HTTP request through a predictable chain. The router maps the URL to a controller action, the controller loads data through models, and a view renders the response, usually HTML built from ERB templates or JSON for an API. Middleware based on the Rack interface sits in front of this chain and handles sessions, cookies and security headers.

The framework is a collection of libraries, each named with an Active or Action prefix. The table below lists the most important components.

ComponentResponsibilityTypical use
Active RecordObject-relational mappingModels, queries, validations, associations
Action ControllerRequest handlingParameters, sessions, redirects
Action ViewTemplates and helpersHTML pages and partials
Active JobBackground job interfaceEmails, exports, slow tasks
Action CableWebSocket integrationLive notifications and chat
Active StorageFile uploadsAttachments stored in cloud or disk
Action MailerOutgoing emailAccount and transactional messages
Core components of Ruby on Rails

Convention over configuration in practice

Convention over configuration means that Rails infers behavior from names and file locations instead of requiring explicit settings. A model named Order maps automatically to an orders table, a controller named OrdersController lives in a predictable folder, and resourceful routes generate the seven standard actions for create, read, update and delete operations.

Generators and database migrations reinforce these conventions. A migration is a versioned Ruby file that changes the schema, so every developer and server can reach the same database structure by running pending migrations. The current schema is also stored in a single file, which makes it possible to rebuild a test database quickly.

Rails ships with an integrated testing framework based on Minitest, with fixtures, system tests that drive a real browser and generators that create test files next to the code. Its security defaults include protection against cross-site request forgery, automatic escaping of HTML output, encrypted credentials and parameterized SQL queries. The benefit is very high early productivity; the cost is that developers must learn the conventions to understand where behavior comes from.

Rails compared with other web frameworks

Rails belongs to the family of opinionated full-stack frameworks, in contrast to minimal frameworks that leave most decisions to the developer. The table compares it with neighboring frameworks in the same Topic.

FrameworkLanguagePhilosophyBuilt-in scope
Ruby on RailsRubyOpinionated, convention-drivenORM, jobs, mail, WebSockets, assets
DjangoPythonOpinionated, explicit configurationORM, admin interface, authentication
LaravelPHPOpinionated, Rails-inspiredORM, queues, scheduling
Express.jsJavaScript on Node.jsMinimal and unopinionatedRouting and middleware only
FlaskPythonMicro frameworkRouting and templating
ASP.NET CoreC#Modular and typedBroad, with dependency injection
Ruby on Rails and comparable server frameworks

Rails traditionally follows a monolithic architecture, which its community defends as the most efficient structure for small and medium teams. It can also serve as a pure JSON backend for a single-page application or a mobile app through API-only mode.

Modern Rails: Hotwire and the default stack

Since Rails 7, the default frontend approach is Hotwire, which sends HTML over the wire instead of JSON. Turbo replaces page loads with fragment updates and streams, while Stimulus adds small JavaScript controllers to server-rendered markup. This is a form of progressive enhancement that delivers interactive interfaces with far less client-side JavaScript than a typical single-page application.

Recent versions also reduce infrastructure needs. Rails 8 added database-backed defaults for jobs, caching and WebSockets, known as Solid Queue, Solid Cache and Solid Cable, plus a built-in authentication generator and the Kamal deployment tool. The table summarizes the evolution of key defaults.

VersionYearNotable change
Rails 32010Merged with the Merb framework, modular core
Rails 52016Action Cable and API-only mode
Rails 62019Multiple databases and Action Text
Rails 72021Hotwire by default, import maps instead of bundling
Rails 82024Solid adapters, authentication generator, Kamal
Selected Rails versions and their notable changes

Limitations and common pitfalls of Rails

Rails optimizes for developer productivity rather than raw throughput. Ruby is slower than compiled languages for CPU-heavy work, although the YJIT compiler has narrowed the gap, and most web workloads are bound by database and network latency rather than CPU time.

  • N+1 queries appear when code loads associations inside loops; eager loading with includes solves most cases.
  • Fat models accumulate business logic until classes become hard to test; service objects or concerns keep responsibilities clear.
  • Callback chains in Active Record can trigger hidden side effects and should be used sparingly.
  • Delayed upgrades across several major versions become expensive, so teams should upgrade one version at a time.
  • Mass assignment risks are handled by strong parameters, which must explicitly permit each accepted field.

A non-technical view

Building a website that stores data, such as an online shop or a booking system, involves many repetitive tasks. Ruby on Rails is a ready-made toolkit that already solves most of them. It works a bit like a well-organized workshop where every tool has a fixed place, so a new worker immediately knows where to find things.

Because Rails follows these fixed rules, small teams can build a working product quickly and keep it organized as it grows.

A concrete example

A three-person team at a regional veterinary clinic network needs an appointment system for twelve clinics. They choose Ruby on Rails because one framework covers the database, staff accounts, email reminders and the public booking pages.

Within the first weeks, they generate models for clinics, veterinarians, pets and appointments, use Active Job to send reminder emails the day before each visit, and use Turbo Streams so the reception screen updates instantly when an online booking arrives. The application runs as a single monolith on two servers with PostgreSQL. The outcome is a production system delivered in about three months by a small team, with no separate frontend application to maintain.