有没有办法创建一个after_confirmation :do_something?
目标是在用户使用Devise :confirmable确认后发送一封电子邮件。
发布于 2010-12-30 07:49:47
devise 3.x新版本的 :
查看不同的答案http://stackoverflow.com/a/20630036/2832282
devise 2.x旧版本的 :
(原始答案)
但您应该能够在用户上放置一个before_save回调(使用观察者的额外积分),并检查confirmed_at是否刚刚由devise设置。你可以这样做:
send_the_email if self.confirmed_at_changed?http://api.rubyonrails.org/classes/ActiveModel/Dirty.html,了解有关检查字段更改的更多详细信息。
发布于 2013-12-17 17:10:40
我使用的是Devise 3.1.2,它有一个占位符方法after_confirmation,在确认成功完成后调用。我们只需要在User模型中覆盖这个方法。
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
# Override Devise::Confirmable#after_confirmation
def after_confirmation
# Do something...
end
end请参阅: Devise 3.5.9源代码:https://github.com/plataformatec/devise/blob/d293e00ef5f431129108c1cbebe942b32e6ba616/lib/devise/models/confirmable.rb
发布于 2012-03-30 04:42:20
您可以覆盖confirm!方法:
def confirm!
super
do_something
end关于这个话题的讨论可以在https://github.com/plataformatec/devise/issues/812上找到。他们说没有像after_confirmation :do_something这样的回调,因为这种方法需要很多不同的回调。
https://stackoverflow.com/questions/4558463
复制相似问题