Spendi with Ruby

Justin Pitts
4 min readOct 9, 2021

Just spent the last couple of months learning how to create and navigate data structures using Ruby in my Flatiron software engineering bootcamp. I really like the way the Ruby syntax makes it easy to read and understand. The lessons in this phase were very in depth with a lot of practice to really help you understand object orientation and association. There were a ton of lessons in this phase and I feel like I gained a lot of great backend coding experience.

Our project assignments were to create our own database using Ruby and display our application with React frontend framework. I’m currently in the process of buying a house so I decided to create a budget application that I called Spendi. This application allows you to track your monthly spending vs your monthly income. You can create a budget category for anything you spend money on. Then you add in your expenses to see how well you’re adhering to your budgets. All of the budget categories you create add up into a total budget at the top of the page which is listed next to your monthly income and total expenses. Your total expenses are subtracted from your budget to give you a remaining budget balance. They’re also subtracted from your monthly income to give you the actual amount of money you have left for the month.

Since this application needed to be specific to each user I created a login page and had to assign the monthly income, created budget categories and expenses to each individual user. In the planning stage of my project I was initially only planning on having two tables. One for the user that had their information and budget, and one for the expenses. As I started to build my database I found the user table was starting to become quite large so I separated the budget categories into their own table. This way I could make the expenses belong to both the user and the budget categories. I attempted to make the user have many budget categories through expenses but found it much easier to just have them belong to the user instead. This way each user has unique categories and expenses. My final schema looks like this.

User Has_many Expense & Categories, Expenses belong_to User and Categories

Building my frontend really helped me decide the final schema for my tables. I started running into some association issues when displaying my data that guided me towards this setup. Fetching my data ended up being the hardest part of this project. I ran into a ton of issues between setting up the paths to the database and fetching the data at the correct time to be able to load the information to the page. The GET requests were fine, the issues arose when I needed to POST, PATCH, and DELETE. Setting up the paths and fetches correctly to send data to the database proved challenging. It was my first time using my own database. In my previous project we just used a simple json server and all of the paths were already setup. I wish there were more lessons on setting these up before our project builds. Luckily I was able to figure it out through checking the data being sent through the request and making sure the user ID was correct.

Delete fetch
Path to Category Budget DB

This was by far my most challenging project yet. It was a great learning experience I feel like I now have a good understanding of utilizing my own database. Ruby is a fun language to work with and I’m looking forward to using Rails in the next phase.

Check out my completed project on Github and my walkthrough on Youtube!

https://www.youtube.com/watch?v=lN4AXDuDH3M&t=16s

--

--