Sinatra Walkthrough guide
Database Design
- We're going to draw out ERD (Entity Reference Diagrams)
- Create a
db\migrations.sql
file.
CREATE DATABASE
\c db_name
CREATE TABLE
- Populate database with test OR production data. We do this with a
db\seed.sql
file.
- Lots of
INSERT INTO
statements!
Creating a Sinatra Application
- We need some files, right?
config.ru
, Gemfile
- What folders?
helpers
, db,
models
, views
, public
, and controllers
Adding Models
- Create a model!
models\name_of_model.rb
- Now, require it in our
config.ru
How do we add controllers?
- Controllers need to be in a
/controllers
folder.
- Name each controller after the resource it represents (hint: ActiveRecord Model names == Controller names)
- The controller class should be ResourcenameController
/controllers/resource.rb
- Each controller should inherit from ApplicationController
- In our config.ru, we need to:
- require the controller -
require './controllers/resource'
- require any model (or helpers) the controller needs
- map a resource (route) to a controller -
map('/resource') { run ResourcenameController }
Videos Reference