6

I am trying to set up Active Job with Rails 4 and Devise. I'm open to any tutorial, if there is any (couldn't find through my searching.)

I know there is a Devise Async gem, but it does not cover Active Job in it. That said, I found this gem that is fresh in development, but I'm getting an uninitialized constant Devise::Async::Backend::Base (NameError)error. (Could be me being airy on implementing it).

Any suggestions are welcomed. I'm hoping I don't have to create new controller methods.

AGirlThatCodes
  • 575
  • 7
  • 21

1 Answers1

13

You can include the following code in your desired model (normally User):

def send_devise_notification(notification, *args)
  devise_mailer.send(notification, self, *args).deliver_later
end

You can take a look at the following page for more detail: http://www.sitepoint.com/devise-authentication-in-depth/

Alexander Karmes
  • 2,438
  • 1
  • 28
  • 34
mrstif
  • 2,736
  • 2
  • 27
  • 28
  • 1
    This appears to be the officially recommended technique now in Devise's README: https://github.com/plataformatec/devise#activejob-integration – stevo Jul 10 '15 at 22:36
  • 1
    hmmm... I take it half-back. As per https://github.com/plataformatec/devise/issues/3550#issuecomment-94248927 (and the method comments https://github.com/plataformatec/devise/blob/2f0002a449a8b9616d51127dc6247bfd8414523d/lib/devise/models/authenticatable.rb#L123), it could be more complicated than this if you're using built-in devise notifications on user creation. `deliver_later` probably only works for previously saved records, not new records. – stevo Jul 13 '15 at 20:04
  • Thanks guys for being active on this. I gave you guys the points since your answer is better than what I ended up going with. – AGirlThatCodes Dec 10 '15 at 14:39