如何使用Devise向Rails新注册用户发送欢迎电邮? [英] How can I send a welcome email to newly registered users in Rails using Devise?

查看:98
本文介绍了如何使用Devise向Rails新注册用户发送欢迎电邮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Devise on Rails,我想知道是否有一个钩子或一个过滤器,我可以使用它来添加一些代码到Devise的用户注册过程,并发送一个欢迎电子邮件给用户后一个帐户已经创建。没有设计它会是这样的...

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆