[Backgroundrb-devel] Major issues with ActiveRecord callbacks in BackgroundRb r324

Olly Lylo list at lylo.co.uk
Mon Mar 17 20:05:33 EDT 2008

Hi there

I've been running BackgroundRb in production for a few months now.  Recently
we added encryption onto some of our ActiveRecord fields by hooking in the
before_save and after_save callbacks, like:

  class MyCallback
    def initialize(attr_names)
      @attr_names = attr_names

    def before_save(model)
      @attr_names.each do |attr_name|
        next if model.send("#{attr_name}").blank?


    def after_save(model)
      @attr_names.each do |attr_name|
        next if model.send("#{attr_name}").blank?
        model.send("#{attr_name}=", Encrypter.decrypt(model.send

There's a little more to it but that should give you the idea.  Anyway,
whilst this works a treat in our Rails app and when using script/console,
BackgroundRb returns strange results when we try and load a model object
which has an encrypted field.  After some debugging it seems like the
before_save filter is called twice for these objects.  When we access it
using the console, it's only called once as expected.

Is there an obvious reason why adding bespoke callbacks like this might
cause a problem in a BackgroundRb worker?   Failing this, would someone be
able to explain (or point me in the right direction of the class files) how
exactly BackgroundRb hooks into Rails?   This way I can dig into the code to

Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20080318/e04b7c5e/attachment.html 

More information about the Backgroundrb-devel mailing list