My Profile Photo

Rachel on Ruby


A blog about my adventures in web development using Ruby.


Struggling with Sinatra

I just published a basic CRUD (create, read, update, delete) application for Learn.Co. It’s titled Home Inventory Tracker and is a simple web application connected to a database that allows you to keep track of the rooms and items in your house, whether for personal tracking or for insurance purposes. If anybody is interested in trying it out for themselves, the repository is located here.

The application is built using Sinatra, which is a DSL (domain-specific language) that helps you build light-weight web applications in Ruby. Sinatra itself is built on Rack, which is a standard Ruby interface for web application frameworks. Because Sinatra is so light, it does not come with a lot of “assumptions” - meaning you are free to customize it how you would like to use it. It integrates with different testing frameworks and html templates, and there are lots of plugins that you can add. Plus, it is easy to write your own plugins. However, this means it can be daunting for someone just getting started (ahem, me). There are lots of tutorials out there (including Sinatra’s own documentation found at www.sinatrarb.com) that are very good and thorough. But when you’re beginning, it’s hard to be sure what you understand well and what you have no clue about.

I made two big missteps early on. First, I started by reading all these tutorials and blog posts and looking at sample applications. This was a mistake for 2 reasons - one, it confused me. Between what I had already learned and all this new information, it became hard to see what the essentials were. Plus, much of the stuff that I read was either outdated, or for the “classic” instead of “modular” type of application. It was hard to recognize what applied to my situation and what didn’t. It also led to my second misstep - my eyes (and self confidence) grew way bigger than my abilities or time available. Ruby is a language that is easy to understand. This can trick me into thinking I understand how something works and how to use it in my own project, when in reality I am several levels away from that. My first attempt at this project was an application with two different types of users with different abilities and permissions. I also started trying to implement my front-end styling right way as well as build a complete test framework alongside the app. We have been using tests in all our lessons so far, but we have not learned how to build our own. We have also learned some styling techniques, but have not practiced how to integrate them in a Sinatra app. Finally, we are just now mastering one kind of user and security and have not even approached the subject of having different types of users. Now, I’m all for challenging yourself. However, when the big challenge is building a complete application all on your own, you need to learn to recognize what is a challenge you can work towards and what is simply idealistic. I should have recognized that trying to do all those new things at once would be too much and actually end up impeding my progress in what I DID know how to do.

I will soon have a follow-up post about how I did end up approaching the project step by step, but essentially I pared it back down to what I knew - one user, one model, one submodel. Then my challenge was building a test framework and integrating all the different parts of a Sinatra application. At the end, I was able to use a little SASS/CSS, but only AFTER the application was completely working on its own. While it is nice to dream big, make sure those dreams aren’t so big that you get lost.

Stay tuned for part two!

comments powered by Disqus