Skip to content

Instantly share code, notes, and snippets.

@dpickett
Created October 8, 2011 19:25
Show Gist options
  • Save dpickett/1272744 to your computer and use it in GitHub Desktop.
Save dpickett/1272744 to your computer and use it in GitHub Desktop.
devise hack with resque mailer
##HACK - dmp - we must return an unserialized version of resource
##so copy devise's method and use a finder for resource
require "devise"
require Rails.root.join("lib/resque/mailer")
Devise::Mailers::Helpers.send(:alias_method, :old_initialize_from_record, :initialize_from_record)
module Devise
module Mailers
module Helpers
include Resque::Mailer
alias_method :old_initialize_from_record, :initialize_from_record
protected
def initialize_from_record(record)
ActiveRecord::Base.verify_active_connections! unless Rails.env.test?
if record.kind_of?(Hash)
#if we use another devise mapping we can't hardcode User
record = User.find(record["user"]["id"])
end
old_initialize_from_record(record)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment