This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

Ruby on Rails Overview Cheatsheet

A high-level architecture cheatsheet for Ruby on Rails: MVC conventions, CLI commands, controllers, views, layouts, and helpers.

· Published

Ruby on Rails is a full-stack web application framework following the Model-View-Controller (MVC) pattern and "Convention over Configuration".

Sub-Cheatsheets in this Guide


Common CLI Commands

# Generate a new Rails project
rails new myapp --database=postgresql

# Start development server on localhost:3000
bin/rails server

# Start interactive Rails console
bin/rails console

# Run database migrations
bin/rails db:migrate

Controller & Action Conventions

class ProjectsController < ApplicationController
  before_action :set_project, only: [:show, :edit, :update, :destroy]

  def index
    @projects = Project.all
  end

  def show
  end

  private

  def set_project
    @project = Project.find(params[:id])
  end
end

Layouts & Yielding

In app/views/layouts/application.html.erb:

<!doctype html>
<html>
  <head>
    <title><%= content_for?(:title) ? yield(:title) : "Default App" %></title>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>
    <%= stylesheet_link_tag "application" %>
    <%= javascript_importmap_tags %>
  </head>
  <body>
    <%= yield %>
  </body>
</html>

References

Related topics