The Quality of Outsourcing October 10th, 2007
We can thank Eric Mill for forwarding this code. Models have been changed to protect the innocent.
<% if Car.find(@driver.car_id).car != nil %>
Model, VIEW, Controller
You NEVER put finders in your view. I know exceptions, but explaining them will be enough justification for some idiot. Look, you put a finder in your view, you're dead to me.
Did they even watch the screencast?
It's remarkable they don't know ActiveRecord relationship macros. That feature converts people to Rails. The column even follows naming conventions! All it takes:
class Driver
has_one :car
end
Then you've got:
<% if @driver.car.car != nil %>
Which only leaves the column name. Wouldn't 'name' be more descriptive?
Truth isn't hard
Last, the coder doesn't know the Ruby definition of truth. Anything except false or nil is true. That leaves us with:
<% if @car.name %>
Which doesn't cover an empty string. You really want:
<% unless @car.name.blank? %>
The moral: don't outsource your code overseas.