I Challenge You Sinatra
I Challenge You Sinatra
I finally finished the Sinatra section of the Learn.co curriculum, and that means I have to make a complete Sinatra app from scratch.
I’ve blogged in the past how being dropped into a project is the best way to learn about it, and this was true in this case as well; I’ve learned more Sinatra in the process of making this project than I did in the whole preceding section of lectures and labs.
The first step of course was coming up with an idea for my project, so last Shabbat I was talking to a developer friend and asked him if he had an idea for a Sinatra app I could make. He started rattling off different ideas and somewhere in between a blog and a fishing app he mentioned “…you could try a reddit clone… actually never mind, that’s probably too complicated…”
I didn’t need anything more than that, and immediately the my wheels started churning thinking of the the different features, models and associations my app would need.
As soon as Shabbat was out I headed straight to my computer and started putting the plan to action.

Freddit home screen
Usually the hardest part is getting started, thankfully this was taken care of by my side project; the Scaffold generator I built for the Corneal gem (read about it here).
My reddit app (which I called “freddit” after Flatiron’s naming convention that gave us “fwitter”) is a very basic clone. It has users that can sign up, log in, start threads called Conversations, reply to other user’s Conversations, edit posts, and some other features which I will describe later.
The complexities came up in the details. I had to come up with methods that would tell my app which user was logged in, and only allow the posts and conversations to be edited by the user that created them.
It got more complicated when I allowed certain users to be “moderators” with the ability to edit posts by any other user, and even to ban a user when needed.

Banned user
Handling all of this complexity led to some pretty ugly looking code, but thanks to some really helpful friends and the great instructors at Learn.co (shout out to MendelB!) I was able to refactor it to something a little more manageable.
If you want to take a look at the code you can find it on GitHub. I would really appreciate any feedback you can offer.
Happy coding!