Rails 设计:after_confirmation [英] Rails Devise: after_confirmation

查看:29
本文介绍了Rails 设计:after_confirmation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法创建一个 after_confirmation :do_something ?

Is there a way to create a after_confirmation :do_something ?

目标是在用户使用 Devise :confirmable 确认后发送电子邮件.

The goal is to send an e-mail after the user confirms using Devise :confirmable.

推荐答案

对于新版本的 devise 3.x :

查看不同的答案http://stackoverflow.com/a/20630036/2832282

对于旧版本的设计 2.x :

(原答案)

但是你应该能够在用户上放置一个 before_save 回调(使用观察者的额外功劳)并检查confirmed_at是否只是由设计设置的.您可以执行以下操作:

but you should be able to put a before_save callback on the user (extra credit for using an observer) and check if confirmed_at was just set by devise. You can do something like:

  send_the_email if self.confirmed_at_changed?

http://api.rubyonrails.org/classes/ActiveModel/Dirty.html 有关检查字段更改的更多详细信息.

http://api.rubyonrails.org/classes/ActiveModel/Dirty.html for more details on checking the change on the field.

这篇关于Rails 设计:after_confirmation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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