设计:在特定情况下是否可以发送确认邮件? [英] Devise: Is it possible to NOT send a confirmation email in specific cases ?
问题描述
def create
super
如果params [:type] ==' xyz
@ user.skip_confirmation_notification!
end
end
但是在这两种情况下都会发送邮件。请告知哪里错误。
所以根据devise可确认模块,您可以通过以下代码跳过发送确认和电子邮件。 / p>
def confirm_your_type_user_without_confirmation_email
#在此处查看您的条件并处理以下
self.skip_confirmation!
self.confirm!
#条件可以在这里结束
end
现在可以在创建钩子上调用它。
class User< ActiveRecord :: Base
after_create:confirm_your_type_user_without_confirmation_email
....
end
有更多的参考,你可以检查:
Devise可确认模块
该解决方案应与上文所述类似。以及避免控制人处理这些责任的最佳做法,因为它不是你的控制器应该采取的。 :)
我希望我的答案会给你一些方法来解决你的问题!谢谢!
Actually I am using devise for login and registration and its working fine, it send a confirmation email which is really good. But I need to send confirmation email in specific cases. I am passing user type in URL and on behalf of that I want to set mail. I have two type of users, one will be confirm their account their self reset of the users can not confirm their account only admin can approve their accounts. I have override the create method
def create
super
if params[:type]=='xyz
@user.skip_confirmation_notification!
end
end
but it sends mail in both cases. Please tell where am wrong.
So according to devise confirmable module you can skip to send confirmation and email by following code.
def confirm_your_type_user_without_confirmation_email
# check your condition here and process the following
self.skip_confirmation!
self.confirm!
# condition may end here
end
Now lets call it on create hook.
class User < ActiveRecord::Base
after_create :confirm_your_type_user_without_confirmation_email
....
end
for more reference you may check this: Devise Confirmable module
The solution should be something similar as I mentioned here above. And its best practice to avoid controller to handle these responsibilities, because its not something your controller should take. :) I hope my answer will give you some way to solve your problems! Thanks!
这篇关于设计:在特定情况下是否可以发送确认邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!