Author Archives

Don’t serialize ActiveRecord objects

ActiveRecord provides a convenient interface for serializing Ruby objects. In the model file, simply declare which column will store the object:

All seems fine until you actually have to retrieve some of the data:

This isn’t the exact code situation I was in, but it’s similar enough.
Here’s how I solved the problem:

The attributes method call returns a [...]

The perils of syntactic sugar in Ruby

I ran into this doozy today:

In math, a+b always equals b+a. Not always the case with Ruby and Time objects.

addthis_url = ‘http%3A%2F%2Fwww.alandelevie.com%2F2010%2F07%2F19%2Fthe-perils-of-syntactic-sugar-in-ruby%2F’;
addthis_title = ‘The+perils+of+syntactic+sugar+in+Ruby’;
addthis_pub = ”;

Trivial Rails tip: easy html spaces

For when you don’t want to type   a dozen times, add this to application_helper.rb:
def nbsp(n=1)
    n.times.map {” ”}
end
In a view:
<%= nbsp 5 %>
replaces
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

addthis_url = ‘http%3A%2F%2Fwww.alandelevie.com%2F2010%2F07%2F16%2Ftrivial-rails-tip-easy-html-spaces%2F’;
addthis_title = ‘Trivial+Rails+tip%3A+easy+html+spaces’;
addthis_pub = ”;

Managing development databases

Today I asked this question on StackOverflow:
My development team of four people has been facing this issue for some time now:
Sometimes we need to be working off the same set of data. So while we develop on our local computers, the dev database is connected to remotely.
However, sometimes we need to run operations on the [...]

FanGamb update

FanGamb is undergoing some exciting changes. Co-founder Rob Shedd writes a bit about it here:
We have some exciting things in the works and as a result, will be moving to Europe later this summer to continue developing our product and business. We can’t yet share all of the details on why we’re making the move, [...]

Setting up Ruby on Linux

Up until now, I’ve done nearly all of my Rails programming on Windows Vista (64 bit). The environment has been pretty good, but it’s time for a change. This was probably due a while ago, but I’ve decided to explore Linux with a dual boot of Ubuntu 10.x.
Thanks to StackOverflow and some Googling, I got [...]