Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 37 ยท Getting Started

What Is Ruby on Rails?

Learn what Ruby on Rails is, why it is called a full-stack framework, how MVC and convention over configuration work, and build a tiny MVC app in plain Ruby.

Ruby on Rails, usually just Rails, is a web framework written in Ruby. A web framework is a big toolbox that handles the boring parts of building a website: reading requests, choosing code to run, talking to a database, building HTML pages, sending email, running background work and more. You write the parts that are special to your application, and Rails supplies the rest.

Rails was extracted from a real product by David Heinemeier Hansson and released in 2004. It has powered sites such as GitHub, Shopify and Basecamp, and many startups. Its big idea is that most web applications are alike, so a framework can make smart default choices for you. In this lesson you will see what Rails includes, how its MVC structure splits an app into parts, and what "convention over configuration" really means. You should know basic Ruby first: classes, modules and blocks appear everywhere in Rails.

The real Rails gem is not installed on this site's runner, so every Rails snippet is read-only. Where it helps, we build small runnable Ruby stand-ins that show the same idea. They are labelled as stand-ins and never claim to be Rails itself.

What does "full-stack" mean?

Some frameworks only do one job, such as routing URLs. Rails is full-stack: one package covers every layer between the browser and the database. The main parts, called components, are these.

One framework, many jobs

Action Dispatch Routes requests to code.
Action Controller Handles one request.
Action View Builds HTML pages.
1 / 3

Because all the pieces are designed together, they fit without glue code. A controller can hand a model object straight to a view, and a form helper knows how to read that object's errors.

The MVC pattern

Rails organizes code with Model-View-Controller:

  • The model holds data and business rules. In Rails, a model is usually an Active Record class that maps to a database table.
  • The view turns data into output, mostly HTML, written in ERB templates.
  • The controller receives a request, asks models for data, and picks a view (or redirects).
flowchart LR
  B["Browser"] -->|"request"| R["Router"]
  R --> C["Controller"]
  C <-->|"read / write"| M["Model"]
  M <--> D[("Database")]
  C --> V["View"]
  V -->|"HTML response"| B

A request enters through the router, the controller coordinates, the model talks to the database, and a view builds the response.

The benefit is separation. A designer can change a template without touching database code, and you can test business rules without starting a web server.

A tiny MVC app in plain Ruby

This is a stand-in, not Rails. It has a model, a controller, a view and a one-line router, so you can see the shape before meeting the real files. Notice how each class has exactly one job.

Ruby Stand-in: MVC in 40 lines of plain Ruby

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with gets), it gets the next line from this box.

In real Rails the router is a DSL (resources :articles), the controller class inherits from ApplicationController, and the view is an index.html.erb file. The division of labour is the same.

Convention over configuration

Rails assumes names line up. If you have a model called Article, it expects a table called articles, a controller called ArticlesController, views in app/views/articles/, and a test file called article_test.rb. Because Rails can guess all of this from the name, you write almost no configuration.

Compare the two styles. With configuration you would declare everything:

Ruby
# read-only: what "configure everything" would look like
Model.table_name  = "articles"
Controller.views  = "app/views/articles"
Controller.model  = Article

With convention, the class name is enough. A stand-in shows the trick: derive related names from one word.

Ruby Stand-in: derive names from one word

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with gets), it gets the next line from this box.

The real framework does this with a much richer set of rules called inflections, which you meet in Rails conventions. The other half of the idea is DRY: "don't repeat yourself". Each fact (such as a column name) lives in one place.

Conventions are defaults, not handcuffs. When a legacy table is called tbl_posts, you can override the name in one line. You only pay a configuration cost where you deviate.

What Rails is good at, and where it is not

Rails shines for database-backed web apps: shops, dashboards, social tools, content sites, internal tools and JSON APIs. It lets a small team ship quickly, and its age means answers exist for almost every problem. Things to keep in mind:

  • Ruby is not the fastest language, so CPU-heavy work (video encoding, number crunching) belongs in other services or background jobs.
  • A big framework has a learning curve. You will use methods that look like magic until you learn the metaprogramming behind them (metaprogramming intro).
  • Rails is "opinionated". If you disagree with its structure, you will fight it.

For a lighter alternative see Sinatra and Rack; for the earlier overview in the Ruby track see Rails overview.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does it mean that Rails is a full-stack framework?

    Full-stack means one framework covers the whole path from request to database to response.
  2. 2. In MVC, which part receives the request and decides what to do?

    The controller coordinates: it asks models for data and chooses a view or redirect.
  3. 3. A Rails model called BlogPost most likely maps to which table?

    By convention class names are CamelCase singular and table names are snake_case plural.
  4. 4. What is the main benefit of convention over configuration?

    Rails guesses table names, view folders and more from class names, so you only configure exceptions.

Summary

  • Rails is a full-stack Ruby web framework with parts for routing, controllers, views, Active Record, jobs, mail, storage and Hotwire.
  • MVC splits an app into models (data and rules), views (output) and controllers (request handling).
  • Convention over configuration means names line up by default, so you only configure exceptions.
  • DRY: every fact lives in one place.
  • Snippets of real Rails here are read-only; the runnable examples are plain-Ruby stand-ins.

Next: Your First Rails App