module Devise::Models::Authenticatable
def send_devise_notification(notification, *args)
end
end
end
message.deliver
else
message.deliver_now
elsif message.respond_to?(:deliver_now)
# Remove once we move to Rails 4.2+ only, as `deliver` is deprecated.
message.deliver_later
if message.respond_to?(:deliver_later)
# Deliver later with Active Job's `deliver_later`
message = devise_mailer.send(notification, self, *args)
def render_and_send_devise_message(notification, *args)
end
@pending_devise_notifications ||= []
def pending_devise_notifications
end
pending_devise_notifications.clear
# could cause multiple emails to be sent.
# after_commit hook can be called multiple times which
# Empty the pending notifications array because the
end
render_and_send_devise_message(notification, *args)
pending_devise_notifications.each do |notification, args|
def send_pending_devise_notifications
private
end
end
render_and_send_devise_message(notification, *args)
else
pending_devise_notifications << [notification, args]
if new_record? || saved_changes?
# For Rails < 6 use `changed?` instead of `saved_changes?`.
# send now because after_commit will not be called.
# delivery until the after_commit callback otherwise
# If the record is new or changed then delay the
def send_devise_notification(notification, *args)
protected
after_commit :send_pending_devise_notifications
devise :database_authenticatable, :confirmable
class User
The following example uses Active Job's `deliver_later` :
deliveries until the after_commit callback is triggered.
you can override send_devise_notification to store the
just after the transaction was committed. To achieve this,
job, sidekiq, resque, etc), you must add the delivery to the queue
if you are using a queue to deliver e-mails (active job, delayed
need to customize the e-mail delivery logic. For instance,
to send a notification/mail. This can be overridden if you
This is an internal method called every time Devise needs
def send_devise_notification(notification, *args) message = devise_mailer.send(notification, self, *args) # Remove once we move to Rails 4.2+ only. if message.respond_to?(:deliver_now) message.deliver_now else message.deliver end end