gpt4 book ai didi

ruby-on-rails - 设计如何覆盖 send_confirmation_instructions

转载 作者:行者123 更新时间:2023-12-02 06:43:05 25 4
gpt4 key购买 nike

我正在尝试重写方法“send_confirmation_instructions”,如下所示:

http://trackingrails.com/posts/devise-send-confirmation-mail-manually-or-delay-them

与:

def send_confirmation_instructions
generate_confirmation_token! if self.confirmation_token.nil?
::Devise.mailer.delay.confirmation_instructions(self)
end

这似乎不再适用于最新版本的设备。设计文档展示了如何覆盖 Controller 而不是模型。关于如何覆盖设计模型有什么建议吗?谢谢

最佳答案

当您设置 Devise 时,您可以告诉它正在使用哪个模型(例如用户);它的许多/大部分方法然后适用于该类。所以这就是你想要覆盖的地方。

这是来自 lib/devise/models/authenticable.rb 上的 Devise 代码的注释,如果我没理解错的话,它几乎准确地描述了您想要执行的操作。

  # This is an internal method called every time Devise needs
# to send a notification/mail. This can be overriden if you
# need to customize the e-mail delivery logic. For instance,
# if you are using a queue to deliver e-mails (delayed job,
# sidekiq, resque, etc), you must add the delivery to the queue
# just after the transaction was committed. To achieve this,
# you can override send_devise_notification to store the
# deliveries until the after_commit callback is triggered:
#
# class User
# devise :database_authenticatable, :confirmable
#
# after_commit :send_pending_notifications
#
# protected
#
# def send_devise_notification(notification)
# pending_notifications << notification
# end
#
# def send_pending_notifications
# pending_notifications.each do |n|
# devise_mailer.send(n, self).deliver
# end
# end
#
# def pending_notifications
# @pending_notifications ||= []
# end
# end
#
def send_devise_notification(notification)
devise_mailer.send(notification, self).deliver
end

关于ruby-on-rails - 设计如何覆盖 send_confirmation_instructions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12831419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com