Flatiron Sinatra Project! Finally finished and how it beat me up.

Chris Houghton
5 min readMay 5, 2021

I have just finished my Sinatra Final Project for Flatiron School and personally, it was difficult, very difficult. Let me explain, I work for two weeks straight. That's 14 days straight no days off and this go around I was also working from 6 pm to 6 am plus a 30-minute meeting and drive time. I was spent, both mentally and physically, what I found most difficult though…was literally e-v-e-r-y-thing!! It’s sometimes rough balancing life, I laugh about it now, but at the time there were lots of words that don't belong written in a blog along with some “, huh, wait, WHAT!” and a bunch of head scratches with ‘what!?’ again and ‘why is it doing this!!!!’ *smashes computer against the wall, moves into the woods with fat bulldog companion eating mushrooms for the rest of his days and finally experiencing peace*, Right I wish.

So not to digress, but for those of you not familiar with Sinatra a quote from the Sinatra Website:

“Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort.”

And some Wikipedia:

Sinatra is a free and open source software web application library and domain-specific language[2] written in Ruby. It is an alternative to other Ruby web application frameworks such as Ruby on Rails, Merb, Nitro, and Camping. It is dependent on the Rack web server interface. It is named after musician Frank Sinatra. -Wikipedia

Basically or not, Sinatra is a Framework or Domain Specific Language(a language written from a base language i.e. Ruby Language) that you can use to develop dynamic web applications. Instead of writing all of our associations and methods and the entire structure of a program and the creating, reading, updating, and deleting methods and the logic blah, blah, blah, etc… The DSL of Sinatra has the methods and tools already available to do so, neat.

What beat me up and back to the initial story at hand was being completely delirious while working on nights, having either limited or no internet for days at a time, contending with 15 hour work days all the while trying to find the time to learn about Sintra and then start on my Sinatra Final Project. I'm not complaining (at least I don't think so) just stating the facts of how every bit of it was a challenge which I accepted gracefully, promise.

So to begin with, what confused me at first was mounting my controllers in the config.ru file, I must have missed this part because this hurt me for a while.

and again whenever I changed the class models which I did way more than I should have.

And then the class associations, and by associations, we are taking ownership and servitude of the class models! My program has an almost militaristic hierarchy thing going on with the User owning many Programs, Programs owning many Routines, and Routines owning many Workouts, Workouts having and belonging to many Exercises, and Exercises belonging to many Muscle classes! The succession of these associations allows the user to build and access many different paths of information!

Then came the validations!

1. Asking for a user to enter a username and password specific to the user, checking if the username is already taken, and then creating a user and a session to store user data to call upon an instance of the said user whenever necessary across the app.

2. Allowing sessions and a ‘session secret’ and writing to the session hash specific pieces of information based on what the user was trying to accomplish.

3. Constantly checking if a user is actually logged in, using a ‘helper’ method I put in my Application Controller so all the other controllers inherited it. The logged_in? helper method validates a user through a key-value pair of the user's object id saved to the session hash, this is created when either the user logs in or signs up. If no session.user_id value than a redirect to the login page every single time a hundred times over and over and over.

4. And checking if the ‘user’ is the owner of the object user is trying to create, edit or delete. We don't want users to type into the address bar a specific address to a different user's information and alter it, that would be chaos and just no. I mean you wouldn't want someone to come into your kitchen and move your cabinets around, would you? Maybe you do I don't know you, but here we constantly check for validations on every step of the process.

The last thing and probably the easiest part of this as everything above this point honestly made my brain hurt inside my skull every day for a week was coding in the logic to the create and edit functions. Apparently, it's commonplace in the world of software engineering to keep our databases as clean as possible and impede users from persisting ‘bad’ data to the database. I didn't go really crazy here, I can see someone really getting in deep on every bit of information the user is allowed to persist. I did just a basic if the box is empty then do not cross go attack to this problem.

All in all, it was a good experience, I learned the most from actually tackling the final than I did the curriculum leading up to it. That's typically how I learn though. My project is called fitness buddy, just a simple app to test some associations and validations. It was frustrating but in the end, I continue to enjoy this adventure I'm on to a better me, thanks for reading.

--

--