Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Quick Server-Side Sinatra Setup

Minimal, elegant Ruby backend without JavaScript nonsense.

Project Structure

my_app/
├── app.rb
├── views/
│   └── index.erb
├── public/
│   └── style.css
├── Gemfile
└── config.ru

Step-by-Step

  1. Install Sinatra
gem install sinatra
  1. Basic app.rb Template
require 'sinatra'

get '/' do
  erb :index
end
  1. Create Views
<!-- views/index.erb -->
<h1>Hello, world</h1>
  1. Run It
ruby app.rb
  1. Production Ready with Rack
# config.ru
require './app'
run Sinatra::Application
rackup config.ru

TODO

  • Add custom routes
  • Add environment config (dotenv)
  • Connect to Postgres

Resources