The Prancing Pages: A Sinatra Project

Ryan Schleck
3 min readMay 20, 2021

If you know me I love fantasy novels, and few have ever been able to compare to The Lord Of The Rings trilogy by JR Tolkien. My dad made me read these when I was a kid, along with The Hobbit (in the correct order) and I think I’ve waited my whole life to find a way to tie this experience into some sort of passion I have. As my time at Flat Iron continued and my passion for coding grew, I finally found an avenue to create something as an homage to these books. Sinatra is a middleware framework for the Ruby coding language that is built on top of Rack. It is used for developing web applications within Ruby. I planned to use Sinatra to generate my own fan site for LOTR complete with user accounts, quotes from the movies, and pictures. Using this saved me a TON of typing out html by generating it dynamically. I even used a tiny bit of CSS to spruce things up. There were a few pieces missing though…

Enter Active Record

Active Record is a MVC model that allowed me to interact with and store Objects using methods that interact with SQL tables. Thru this use of this database my program gained a sense of permanence. I used sqlite3 as my SQL adapter that Active Record interacted with to store objects in related SQL tables. I found table relations particularly fascinating, here is the one I used for my project:

crudely drawn (was intended for personal reference only) but you get the idea.

As you can see I knew that Users would have many Comments, as would Characters. I knew that Users would have many Characters thru Comments and vice versa. As of right now I have not yet implemented Quotes or Favorite Quotes but that is coming. Thanks to The One API I was able to save literally hundreds of quotes from this trilogy and map them to characters. I received this data as JSON which I then parsed through and used to initialize instances of my Quote class. For personal reasons I decided to exclude The Hobbit movies from my project.

Another factor I ran into whilst building The Prancing Pages was the fact that Users had to create passwords upon signing up. It is never a good idea to store user passwords as plain text even if your database is hidden from the internet. I used a Ruby gem (coincidentally called bcrypt) that uses bcrypt encryption. Thanks to this gem all of the Users passwords in my database were protected against various cipher attacks and prying eyes.

This is definitely something I intend to work on in the future, I just had way too much fun building it to let it just be a school project. I’m enjoying my journey at Flat Iron thus far and can’t wait to see the next phase and push myself further. The things I am learning are fascinating especially when I get to see them all come together like this project has shown me.

--

--