Rails, callbacks, workers, and the race you never expected to lose

August 21, 2012 § 38 Comments

Consider a fairly normal pattern in a user model in Rails, sending a welcome email when a user signs up. If you’re interested in keeping your controller actions quick whilst you do this, you would probably queue the email to be sent later, like this:

class User < ActiveRecord::Base
  
  after_save :queue_welcome_email, :on => :create
  private
  def queue_welcome_email
    Resque.enqueue(WelcomeEmailJob, self.id)
  end
end
class WelcomeEmailJob
  @queue = :normal

  def self.perform(user_id)
    user = User.find(user_id)
    UserMailer.welcome_email(user).deliver
  end
end

Straightforward, right? You’d think so, but if you implemented this and ran it in a live system, you would find a small number of ActiveRecord::RecordNotFound errors cropping up in Resque.

« Read the rest of this entry »

Cross domain font woes in Firefox

March 21, 2012 § 5 Comments

We love using custom fonts with CSS @font-face declarations and have done so on a number of our recent projects. One thing has caught us out on a couple of occasions though. Here’s the scenario:

You’re building a site, everything is going well with the styling. Your custom font is looking good on your local version of the site, it’s been checked in staging and looks good there. You launch the site, it looks good everywhere… except Firefox. Your favourite development browser (well, mine at least, apparently some people like Chrome a lot these days) is no longer showing that lovely font. You can’t reproduce this on your own machine, everything seems lost.

« Read the rest of this entry »

You fight like a dairy farmer! Some Twitter whimsy with Ruby

March 14, 2012

When I was a kid I used to love playing The Secret of Monkey Island. I played it on my Commodore Amiga 500 and it came on four 3.5″ floppy disks. Those were the days.

My favourite part of the game was the , where, instead of strength, a sharp wit was the only way to overcome your opponent. The insults range from derogatory (“You fight like a dairy farmer!”) to egotistical (“I got this scar on my face during a mighty struggle!”) and you take the lead character, Guybrush Threepwood, through a number of fights to learn them all.

Fast forward to today and with the power of Twitter and a few lines of Ruby we can recreate insult sword fighting for the modern world!

« Read the rest of this entry »

I don’t like the Ruby 1.9 hash syntax

June 20, 2011 § 67 Comments

There, I said it, I don’t like it. And I don’t know why you do either.

I assume you like it anyway, everyone else I talk to seems to. My heart sank over and over again whilst I was at the recent and saw respected rubyist after respected rubyist using the new Ruby 1.9 hash syntax in their presentations.

I just don’t get it.

But I’m not one to just moan. I plan to justify my feelings. Then maybe you can tell me why you do like it?
« Read the rest of this entry »

Powder: making Pow even easier!

May 25, 2011 § 5 Comments

Pow is the hot new zero-config server released by the benevolent guys at 37signals. They created it to make all of our lives easier because you no longer have to think about application servers in development with Pow. Obviously thin, unicorn, passenger or whatever your choice of production server is are still important, but Pow makes your local environment easier to deal with.

But is it really easy enough?

« Read the rest of this entry »

Follow