根据数据库中定义的角色在 Devise 中发送自定义确认电子邮件
我正在使用 Devise 注册一个可确认的网站。然而,我在这个网站上扮演着两个不同的角色。第一个角色是使用常规 Devise 注册过程的“主要”角色。第二角色的帐户应该在原始用户确认其帐户、首次登录并保存某个模型后创建。例如,如果用户注册该网站(作为角色类型 1),则会正常收到来自 Devise 的确认电子邮件。接下来,他们访问确认链接,验证他们的帐户,然后填写一份表格,在其中指定一些也应该获得帐户的朋友。朋友是角色类型 2,他们应该收到一封与为朋友注册帐户的原始人不同的确认电子邮件。当保存原始用户填写的表格时,就会创建朋友的帐户。此外,一个人可以稍后编辑和添加更多朋友,因此可能还需要在相关表单/对象的更新方法上创建帐户,并且需要向这些新用户发送正确的电子邮件。需要明确的是,我不想跳过确认 - 我只想根据用户的角色向他们发送不同的确认电子邮件。我不知道如何正确处理这个问题。如果我尝试在使用 User.new 保存表单时在代码中创建朋友帐户,请调用 user.skip_confirmation!会自动确认它们。但是,我不希望任何人自动确认 - 我只想根据各种条件选择不同的可自定义确认电子邮件来发送。有人能指出我正确的方向吗?
I am using Devise for registration of a site with confirmable. However, I have two different roles for this site. The first role is the "main" role that uses the regular Devise signup procedure. Accounts in a second role are supposed to be created after the original user confirms their account, logs in for the first time and saves a certain model. For example, if a user signs up for the site (as role type 1) the get a confirmation email from Devise as normal. Next, they visit the confirmation link, verify their account and then fill out a form where they specify some friends that should also get accounts. The friends are role type 2 and they should get a different confirmation email than the original person who signed up their friends for the account. The accounts for the friends are created when the form filled out by the original user is saved. In addition, a person can edit and add more friends later so accounts might also need to be created on the update method of the relevant form/object and those new users will need to be sent the correct email. To be clear, I do not want to skip confirmation - I just want to send different confirmation emails to the user depending on their roles. I cannot figure out how to handle this properly. If I try to create the friends accounts in code when the form is saved with User.new, calling user.skip_confirmation! will automatically confirm them. However, I do not want anyone automatically confirmed - I just want to select a different customizable confirmation email to send depending on various conditions. Can someone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 /gems/devise-xxx/lib/devise/models/confirmable.rb 中查看
send_on_create_confirmation_instructions
方法及其注释Check out
send_on_create_confirmation_instructions
method and comments for it in your /gems/devise-x.x.x/lib/devise/models/confirmable.rb