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

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

问题描述

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

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    # <======= 
  ...   

推荐答案

我使用回调方法解决了这个问题.这不是最干净的解决方案,不如观察者干净,但我会接受.我很幸运 Mongoid 实现了 ActiveRecord 回调!

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天全站免登陆