Po skonfigurowaniu Devise, możesz powiedzieć, który model działa (np. User); wiele/większość jego metod stosuje się wtedy do tej klasy. A więc tam właśnie chcesz zastąpić rzeczy.
Oto komentarz kodu Devise pod numerem lib/devise/models/authenticatable.rb
, który opisuje prawie dokładnie to, co chcesz zrobić, jeśli dobrze czytam.
# 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
Dzięki, więc mówisz, dodaj "send_devise_notification" do mojego pliku user.rb? Próbowałem tego i nie zostałem wywołany ... – AnApprentice
Tak, nadpisuj 'send_devise_notification' w swoim modelu użytkownika. Udało mi się przechwycić powiadomienie (właśnie wysłałem coś do dziennika, aby to sprawdzić) z aktualną wersją Devise. Ale aby wszystko działało, przeczytaj komentarz - nie jest to tylko kwestia zdefiniowania metody, musisz również dodać filtr 'after_commit', aby zbudować kolejkę z opóźnionym zadaniem (lub czymkolwiek innym). –
Dzięki, ale nie w tym miejscu jest "send_confirmation_instructions"? i muszę zmodyfikować tę metodę "send_confirmation_instructions" – AnApprentice