My first Sinatra app

Ohletamyleta
3 min readFeb 9, 2021

For my phase 2 project at Flatiron School, the assignment was simple: take all of my recently acquired knowledge about Active Record and Sinatra and create a fully functional web based app. It was recommended to find a domain that we were familiar with, and that would fit the project specs. As a currently Covid-sidelined theatre geek, I decided to create a way for my fellow actors and technicians to track shows that they either had done or wanted to do in the future. Stage Dreams was underway!

Ground Zero: What in the heck am I doing?? How do I even start??

Simple in theory — but how was I going to create the base structure? What gems to include, what files to add, and how was I going to figure out the css styling?Enter Corneal (available here). Specifically designed by a former student to assist others with getting a Sinatra app framework in place, Corneal made getting started so much easier! Not just because it has a fabulous logo with Old Blue Eyes himself overseeing my project:

Nobody sings like this guy.

But because it gave me a familiar framework to start my build in:

As a student, most of these frameworks are already built into the labs we work through. It was fantastic to have the basics laid out for this first attempt, and I can see myself using Corneal again in the future if I need to mount something in Sinatra — it’s a terrific place to start!

Building out the basic CRUD functionality was actually pretty easy (except for one wayward “}’ that broke everything in the shows controller, but I found it. Eventually.) Adding in a handful of Helper methods streamlined validating access to the user pages. Part of the requirements for this app included making sure only authorized users could view/edit/delete the shows they had created, so I built these helpers into the application controller:

Like the flash says, you need a ticket to get in!

Once I employed these methods in the controllers, only logged in users could access the app — requirement satisfied! But I also wanted to expand a bit beyond the basics. Being a little intimidated by css stylings, I dipped a toe into the stylesheet and the home page, and made two changes: the background color went from light blue to purple (it’s my favorite, so I figured why not?), and I added an image to the home page:

I also added a random quote generator to the user’s home page — created an array of theatre quotes about dreams, and used the Array.sample() function — so every time the user is directed to their list of shows, they see a different quote for inspiration. The last addition was the installation of the sinatra-flash gem (available here) to generate messages when actions were executed. These custom messages are also theatre related, to keep the user entertained while serving a practical function (when a new user registers successfully, the app displays the opening verse of “Wilkommen” from Cabaret). Things like this are why it was so important to choose a domain that I knew and enjoyed! This could have been a very flat app, without much focus on the end user, but it turned out to be both functional and fun!

Feel free to check out my repo on github here.

--

--

Ohletamyleta

Software engineering grad, theatre geek, master punster.