【发布时间】:2015-07-03 09:25:11
【问题描述】:
在我的 Rails/Devise 应用程序中,我需要为具有特定角色的用户手动发送确认电子邮件并延迟其发送。
我现在要做的是: a) 在 User.rb 中:
before_save :skip_mail_if_role1
def skip_mail_if_role1
self.skip_confirmation_notification! if self.role == 'role1'
end
b) 在此角色用户的自定义注册控制器中:
Devise::Mailer.confirmation_instructions(resource, resource.confirmation_token).deliver_later(wait: 5.minutes)
当然,我收到一封带有错误令牌的电子邮件,并且单击按钮什么也没做。任何虚拟令牌也不做任何事情。当我没有传递第二个参数时,我得到参数错误(至少应该有 2 个参数,这很奇怪,就here 他们只传递 user 参数)。
所以我想知道我要从控制器那里传递什么作为令牌来完成这项工作?
更新:
使用this 指令我实现了自定义设计MyMailer,但我仍然不知道在调用MyMailer.confirmation_instructions(resource, ????).deliver 时应该在控制器中传递什么token 属性
【问题讨论】:
-
使用 user.reload 获取最新生成的令牌
-
@Milind
user.reload不会更改令牌 - 它仍然相同并且仍然错误
标签: ruby-on-rails email devise token devise-confirmable