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 »

We’re giving away a ticket to RubyConf 2011 in New Orleans!

September 21, 2011 § 15 Comments

At Mint we’re lucky enough to have a fantastic conference policy that gives us the opportunity to go and hear from experts in our respective fields, meet our peers and sometimes even see another part of the world.

One of our favourites is Rubyconf in New Orleans. As well as being one of the best Ruby conferences out there, it takes place in one of the most amazing cities in the U.S.

Can I come?

Yes, we want to share the love and are offering one lucky person a ticket to Rubyconf. All you have to do to be in with a chance of winning is tell us in the comment section why you think we should choose you. The best/funniest answer wins. Easy.

The competition closes Friday at midnight (EST) so get commenting…

*The winner is responsible for their own travel and accommodation. 



            

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 »

Where Am I?

You are currently browsing entries tagged with ruby at Logical Friday.

Follow