Project 3: Rails

Ikenna n
3 min readMay 18, 2021

Before starting this program, I have heard rumors that it could sometimes take a person an hour to do one line of code.
“How ridiculous,” I thought.

Little did I know, on May 14, 2021, that person would be me.

The app I created for this project was called Feelings. The idea for the application was inspired by my own journey. Over the past few years, I have been working to try and understand my feelings and keep track of my wellness goals: drinking water, going outside, eating, etc. On paper, these goals seem so easy to remember. But, when you’re caught up in the hustle and bustle of everyday life, these goals can be quickly forgotten. In this application users complete feeling logs, which record how the user is feeling and their responses to questions. These variables will later be analyzed to then find correlations between them. Users can view all of these logs on the Feelings Log tab, which is an index of all the logs complete by the user.

One functionality I wanted to add to my application was a tab called “How’s Everybody Doing”. The idea would be that the page will show the most logged feeling that day and by how many people. The concept was easy enough, but finding the pieces that would bring everything together proved more difficult than anticipated.

The first issue was trying to find a way to gather all the logs that were created that day, a day being defined from Midnight to 11:59 pm. At first, I thought I would need to group by today’s date. But after 10–15 minutes, I was not returning the values I needed in the proper format.
“Rather than trying to do this yourself, why don’t you try and see if someone else has tried to do the same thing?”, I asked myself.
Sure enough, part of the answer to my puzzle was on StackOverflow. Turns out, I didn’t need to group by date where I could simply look for logs that were made in between a specified time frame (ie. a range)! Once I figured that step out I needed to figure out how to find that most popular feeling logged that day. This is where ‘.group’ would come in because I needed to group all of the logs that were made today by feeling_id, the attribute associated with the different feelings in my database. Then, I needed to count those groupings and return the one with the highest count. What surprised me was the result of all of these methods came back in an array, the first being the id of the most popular feeling, and the second being the count of how many times the feeling was logged. Using those numbers I was able to build out my “How Is Everybody Doing Today” functionality.

This took me an hour. A full hour. From trying to figure out the syntax to changing the right methods together, and figuring out the appropriate methods to use and where. However, despite the time it took, I found myself loving the process. It was exciting to try to find the right combination of words to unlock the information I needed. They say time flies when you are having fun…who knew this much fun would only produce one line of code!

--

--