如何使用Devise向Rails新注册用户发送欢迎电邮? [英] How can I send a welcome email to newly registered users in Rails using Devise?
本文介绍了如何使用Devise向Rails新注册用户发送欢迎电邮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
respond_to do | format |
如果@ user.save
Notifier.welcome_email(@user).deliver#< =======
...
我通过使用回调方法解决了这个问题。
解决方案
这不是最干净的解决方案,不像观察员那么干净,但我会接受的。我很幸运Mongoid实现了ActiveRecord回调!
after_create:send_welcome_mail
def send_welcome_mail
Contact.welcome_email (self.email,self.name).deliver
end
I am using Devise on Rails and I'm wondering if there is a hook or a filter that I can use to add a bit of code to Devise's user registration process and send a welcome email to the user after an account has been created. Without Devise it would be something like this...
respond_to do |format|
if @user.save
Notifier.welcome_email(@user).deliver # <=======
...
解决方案
I solved this by using a callback method. It's not the cleanest of solutions, not as clean as an observer, but I'll take it. I'm lucky Mongoid implemented the ActiveRecord callbacks!
after_create :send_welcome_mail
def send_welcome_mail
Contact.welcome_email(self.email, self.name).deliver
end
这篇关于如何使用Devise向Rails新注册用户发送欢迎电邮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文