Using Sinatra to build a Case-Tracker

Sep 6, 2018 · 2 min read

A big part of learning web development is understanding programming languages and how to use them. In my coding bootcamp, Flatiron, one of the projects to complete is to build an application based on Sinatra.

Sinatra is a Domain Specific Language implemented in Ruby that’s used for writing web applications, created by Blake Mizerany. Most importantly, in my opinion, it is the best way to establish a foundation of understanding MVC (Model, View, Controller) before tackling Ruby on Rails.

My project is very simple. I built a web application that manages case loads on a very basic level. I used Sinatra to do it. I implemented SQLite3, ActiveRecord, RESTful routes, CRUD actions, and HTML. In this blog, I will go through and breakdown the thought processes and code formation used.

To begin…

ActiveRecord is the database toolkit for Ruby. ActiveRecord is the M for Model in MVC. Basically, when the model inherits from ActiveRecord::Base, the models inherit a whole bunch of functionality. A whole bunch of methods you don’t have to write because it would… take…. foreveerrrrrrrrrrrrrrrr!

class class_name < ActiveRecord::Baseend 
#inheriting methods from ActiveRecord::Base

This means that using this inheritance allows us to bypass writing setter/getter methods, validations of models, associations between models, allows us to communicate with the database, and much, much more.

RESTful Routes & CRUD. Now, I’m sure you’re asking yourself… what? Haha.. I asked myself the same thing. RESTful is a convention on how we handle HTTP verbs and URLs in the C for controller in MVC. Here is a controller using RESTful conventions and CRUD(create, read, update, delete) actions:

class Controller# GET: /cases# GET: /cases/new #Create# POST: /cases# GET: /cases/5 #Read# GET: /cases/5/edit #Update# PATCH: /cases/5# DELETE: /cases/5/delete #Deleteend

HTML/VIEWS. How do we see all the magic happen??

The V for View in MVC is how we see the code put together in HTML files in addition to using ERB tags. These files which turn into website pages are what the clients can see to get or view information.

Now, of course, there is a lot more of intricate details that go into building glorious applications, but this is the base.

Here is my github repo for the project: https://github.com/BrittanyTinnin/sinatra-case-tracker

Enjoy!

Brittany Tinnin

Written by

Full Stack Web Developer | Software Engineer | tinfullstackdev@gmail.com | Ruby, HTML, CSS, Javascript, Rails, React, & Redux | Tampa

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade