Phase 4 — Ruby on Rails

Justin Berger Howes
3 min readFeb 12, 2022

Rails… Rails…. Rails

Let me start off by saying Ruby on Rails was NOT my favourite framework to work with. However, 4 months ago me was a naive and ignorant brat. I am now a Rails-liever (it can be a thing).

In between a sick kid, a sick wife and a sick self, working full time up to the Christmas period as a chef and coding whenever I could keep my eyes open, Rails was a handful to learn.

The (simple) analogy of customers, waiters and chefs to explain rails went way over my sleep deprived head but, as with all things, good things take time. To fully grasp Rails, unfortunately, all it took was the grunt to keep trying and googling and a little help from the O’Reilly Learning Rails 5 — Rails from the inside out, by J. Mark Locklear.

Now. Spendr.

Spendr is something that I have had in the back of my mind for a while now, after losing so many receipts for deductions at tax time or petty cash at work. Unfortunately, the idea has already been implemented into a few banking applications, however Spendr is a bit more hands on.

In a nut shell, Spendr is a purchase tracking system. It allows the user to log an itemised receipt, categorise and make notes for each item as well as the receipt as a whole. Particularly useful if you cant for the life of you remember why you bought 50 permanent markers from Officeworks last year.

Honestly, I think Spendr will work better by using Rails as an API and rethinking the models, but for now, I think it does what I wanted it to and I am happy with the end product.

Polymorphic associations….

The ability to write, for example, notes, on a receipt, but on an item is a concept that can be complicated. Thankfully, we have polymorphic associations(how cool does that sound, right?). Polymorphic associations basically allow a model to morph its “personality” — if you like — depending on the situation in which it is being used. Here’s an example of a migration to make such a model.

Take note of the magic line t.references :notable, polymorphic: true, index:true. This right here is the good stuff. Pair that with some nested routes such as:

And controllers and nested controllers and a simple form, they’re pretty straightforward.

Obviously, this is a very shallow view of the monster that is the polymorphic association (chills, right?) and I suggest having a much deeper dive into the topic.

All in all, Rails was a bumpy but rewarding road for me and I look forward to many more years of working with it.

JBH

--

--