What I Learned From Building My Very First Rails Application
In all honesty, this one was tough. I never really have difficulty finding inspiration. Whenever a project comes my way, I basically just start scribbling an ERD like a madman. This one didn’t come easy, however. I was drawing a blank until I brought up my project in a casual conversation with my sister, Salma, who is a pelvic floor therapist(https://www.instagram.com/salma.pelvicfloortherapist/?hl=en). She suggested creating an application geared towards assisting physical and occupational therapists, also mentioning that these kinds of applications are abuzz in femtech circles. Even with a great idea like that, the models still didn’t sit right with me, but I went with it anyway. Oh, how I wish I hadn’t.
The basic idea of Physio is to allow rehabilitative therapists to add a patient and a diagnosis based on location, and if they so choose, to assign rehabilitative exercises to that patient. Brilliant, I know.
The backend went swimmingly enough, save an issue with some gem extensions. I created a seeds file, migrated my tables, and created the resources without a hitch. User authentication and bcrypt was still familiar from sinatra so that was fairly simple. I created simple validations for my models, mainly just ensuring that input was present, at the very least.
Creating the routes was fairly simple as well. Nested routing, something that I had a bit of trouble grasping, took a bit of time but I managed to properly check for the presence of the parent resource in the child controller. It wasn’t until omniauth did I really hit my first snag.
The tricky thing with omniauth is that there is little room for deviation. There are a lot of small, sequential steps that have to be followed. The first issue was getting the client ID and secret from Google. For some reason, I had to delete my project the first time and recreate it to get the proper keys. Then the next issue was getting the route working properly. I must’ve tried at least a dozen combinations until getting it right, but when I did — man, was that satisfying.
Then I had to run checks to ensure that a user couldn’t manipulate the URL to access different users or patients information, which would be a serious confidentiality issue. So I wrote a few private methods in my controller. Then, it happened.
There was this really evasive bug that I couldn’t get to the bottom of. It wasn’t until I got the help of one of the tech coaches did I track it down. Usually, after debugging something, I do my happy dance, but not this time. The reason that bug was there was because there was a fundamental flaw in my design. I knew that my initial design didn’t sit right with me, but I ignored that instinct. That is a mistake I won’t make again.
At this point I had a choice. Either find a way to patch this up and submit a half baked but still somewhat functional application, or start over. For me, the former was no option at all. I couldn’t, in good conscience, put forth something with a shoddy foundation. That would definitely keep me up at night, but so does starting over, as it turns out. Despite this mistake being entirely my doing, I was pretty frustrated.
I told myself, sure I can give up. I can go back to being comfortable and complacent, or I can stop feeling sorry for myself and start over. If this somehow happens again, I start over again and again and again until I get it right. I’m guessing my future self will thank me for not giving up, but that remains to be seen.
I allowed myself to wallow and mope for a couple of hours, then I went straight back to my desk and recreated an ERD that made sense. Because I had my old repo, doing it the next time around was a lot easier. Now that Physio is up and running, I can say with conviction that I have do not regret starting over. Sometimes you have to knock something down to rebuild it even stronger.