當您設置Devise時,您告訴它它正在處理哪個模型(例如用戶);許多/大部分方法適用於該類。所以這就是你想要重寫內容的地方。
這是來自lib/devise/models/authenticatable.rb
的設計代碼的評論,它描述瞭如果我正確閱讀,幾乎到底要做什麼。
# 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
謝謝你所以你說要添加「send_devise_notification」到我的user.rb文件?我試過了,它沒有被調用... – AnApprentice
是的,請覆蓋User模型中的'send_devise_notification'。我能夠用當前版本的Devise攔截通知(我剛剛發送了一些警告來證明它可行)。但要使所有的工作都能正常工作,請閱讀註釋 - 這不僅僅是定義方法的問題,您還必須添加'after_commit'過濾器來構建延遲的作業(或其他)隊列。 –
謝謝,但這不是「send_confirmation_instructions」所在的地方嗎?我需要修改該方法「send_confirmation_instructions」 – AnApprentice