They said “just use a PORO” but I don’t know what that is

Does this sound familiar? Asking for advice on a forum – “I’ve got a bulk update task for my database and I’ve read that I shouldn’t put that sort of thing into a migration – what’s the best way to do it?” And the reply came back – “Just use a PORO”. I looked it… Continue reading

How do you read other people’s code?

When you’re starting out, one of the best ways to learn is by looking at code written by more experienced developers; especially when it comes to learning key concepts like “the Rails Way”. But where do you begin? It can be a struggle to figure out how a particular app works when you have loads… Continue reading

What is Monkey-Patching?

As you read about Ruby you’ll often see the term “monkey patching”. It’s used all over the place by experienced Rubyists but it’s one of those dangerous things that is very easy to misuse or abuse. So if you’re confused about what it is, here’s a quick explanation: Ruby is an extremely dynamic language. That… Continue reading

What is duck-typing?

You often hear Rubyists talking about “duck-typing” But what is duck typing? What do ducks have to do with ruby anyway? In many programming languages, each object, or variable has a static type. By static, we mean it is determined at the time that the code is compiled. So you define variable s as a… Continue reading

What is a join model? Or has_and_belongs_to_many versus has_many through

Figuring out the associations between your models can be one of the hardest things to wrap your head around. Rails’ ActiveRecord library presents your database as a series of objects; the relations of a relation database converted into associations. Which, on the surface, makes dealing with databases a piece of cake. But in reality it… Continue reading

Joins, associations and relations: the database underneath your ActiveRecord models

Have you ever had issues wrapping your head around associations between your models? Do you need a join model? What is a join model? What is a join? How do you set this stuff up? Relational databases are structured into tables. Each one is basically a spreadsheet – a fixed number of columns and a… Continue reading

Why is to_s not returning an object ID and not what I told it to?

to_s is one of the most useful methods in Ruby. Almost every class you ever write should have an implementation of it; it’s useful when debugging, it’s useful when outputting information for people. But sometimes you call puts @my_object and it ignores your to_s method and just returns the object ID; something like #<C:0x0055ff9f85ba48> Why?… Continue reading