Off the rails!?

Mr KLT
3 min readOct 3, 2021

I found it difficult to understand on rails when we first started phase 4. I didn’t fully understand active record and databases from the previous phase and felt a little overwhelmed with all the new information.

I think also because of covid and lockdown, I was not as attentive during our lectures and had less time for the labs, making it difficult to follow and complete a few days later. I was definately a little bit worried when we got to project week and was wondering how I was going to complete the project?!

I had a rough idea of what I wanted to build based no the project requirements. Having recently moved houses I decided to create a Airtasker like app for creating and bidding on jobs.

I began with the basics, creating a User model as that would be required no matter what I built. I created a basic model file and then thought about what might be required. The last few labs we had revolved around logging in, sessions and passwords. As they were the freshest in my mind, I worked on implementing them into my app as soon as possible to get them right.

A lot of trial and error happened when creating the MVC for the user, I struggled with it until I found out I could see what was wrong and what params were being passed using the terminal. When I saw what my id was actually being passed back and what it should be, I was able to quickly fix my code so a user could create an account and also sign in. I added a nice profile page and the ability to edit their profile details and felt pretty good with myself :)

Next step was creating the Job MVC, that was easy now that I had gotten better writing my own User MVC, next step writing a nested route, I initially thought that was going to be difficult but it was very simple. Running rails routes really helps speed up the work flow with easy to understand url helpers.

My next big hurdle was deciding what my has many through relationship should be? I settled on creating a Bid class that had a bid amount and comment attribute as well as the id of the user. To differentiate between a user who bid on a job and a user who created a job, I created 2 new models poster and bidder which belonged to user model. These 2 models would help make it clearer who was who. I refactored my User and Job models to account for the new models and relationship and was able to test out this new relationship…

I had a lot of difficult correctly assigning the correct bidder/poster to the job/bid they had created, what I realised is that I was trying to set the bidder/poster _id to the wrong attributes which caused my models to never save correctly I hadn’t realised this at first because I only had 2 users and even though the bids and jobs were being assigned the wrong IDs it wasn’t noticeable cause there weren’t enough Posters/Bidders for it to be noticed. I only found this out when I created multiple users models in the Seed file and saw that the create methods were no longer working when I tried to create a bid or job. The error message returned in the forms would say “Bidder does not exist” or “Poster does not exist”. I finally figured out that it was happening because I was trying to set it with the wrong ID!

After that I worked on adding in Oauth, I was spoilt for choice with so many oath providers but found the instructions very unclear. A quick search on YouTube took me to a tutorial from Flat irons on how to add oauth to rails! Win!! There was a lot of information there that I wouldn’t have understood if I had just read through the instructions I found on other websites through google.

With the boxes ticked, I spent the rest of my time tidying up my code and fixing any bugs that arose through testing and refactoring code.

Overall I really enjoyed this project, more so than the HTML/CSS and Ruby project. It probably sits just below the React one. It was a great project to teach me about how to build back-ends, further my knowledge on relationships and databases. I wonder if the other frameworks are as good for php and java?

--

--