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

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

Which is the best way to add a feature to my application?

The other day, someone asked: I’m building an application for rating college lecturers; should I allow the users to populate the lecturer’s information themselves or should I load it up myself? You know what? I can’t answer that. Probably, you can’t answer that. Like so many things, it depends. You need to think about the… Continue reading

How to write your first acceptance test

Rubyists always talk about testing. The growth of Ruby (and Rails) came at a time when automated testing and agile development also came to the fore. And much of the flexibility around agile depends upon being able to safely make changes to your development plan after the project has started. But testing is not easy…. Continue reading

How do I check that the value of a field against the legal values in a file?

What if you were writing an online store, selling T-shirts, for your client and wanted them to be able to add in new stock? You could add in a model for shirts and let the store administrators add in new items via the admin section. But in order to save time and reduce errors, you… Continue reading

The easy way to get started with automated testing

You love Ruby. A beautiful language, object orientated with a light sprinkling of functional features. The community is nice. But there’s a nagging doubt in the back of your mind. Real Rubyists use tests TDD, BDD, RSpec, Capybara … you’re not a rubyist if you don’t write tests. That’s what the cool kids say. And… Continue reading

2 things every ActiveRecord model needs to know

If you’re an ActiveRecord model, life’s pretty easy. Find yourself here, save yourself there, validate yourself every now and then. But there are two questions that every ActiveRecord model needs to know the answer to, otherwise they find that they’re just that bit awkward when dealing with the outside world. The first is pretty easy… Continue reading