Rails:Devise:用户确认注册后发送电子邮件 [英] Rails: Devise: Sending an email after user comfirms registration
问题描述
我的应用程序正在使用Devise,并正确发送确认电子邮件,并在点击确认链接后确认用户。我还想在用户确认后发送第二封电子邮件。
My application is using Devise, and is sending out confirmation emails properly, and confirming users properly as well after they click on the confirmation link. I would also like to send a second email AFTER the user is confirmed.
有关如何延迟确认或两步确认但是没有任何建议关于我正在寻找什么(我可以找到)。
There is a lot of advice on how to delay confirmation, or 2-step confirmation, but nothing on what I'm looking for (that I can find).
Devise :: Module :: Confirmable文档告诉我,使用的方法是确认!我不知道该怎么做任何想法?
The Devise::Module::Confirmable documentation tells me that the method to use is confirm!, but I am not sure how to do this. Any ideas?
推荐答案
Rails Devise:after_confirmation
只需定义一个after_save回调,检查用户是否被确认,如果是,则发送电子邮件。
Simply define an after_save callback that checks to see if a user was confirmed, and if so, sends the email.
如果要保存几个CPU周期,可以使用以下操作覆盖Devise ConfirmationsController:
If you want to save a few CPU cycles, you could override the Devise ConfirmationsController with something like this:
class ConfirmationsController < Devise::ConfirmationsController
def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
if resource.errors.empty?
set_flash_message(:notice, :confirmed) if is_navigational_format?
sign_in(resource_name, resource)
# Send the user a second email
send_post_confirmation_email
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
else
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
end
end
end
这篇关于Rails:Devise:用户确认注册后发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!