Rails设计,如何跳过确认电子邮件但仍然生成确认令牌?

我正在使用

user.skip_confirmation! 

在现有用户添加新用户时跳过设计电子邮件确认。 skip_confirmation的问题是它不会生成确认令牌。

我想手动发送确认电子邮件,这意味着我需要一个确认令牌。

如何跳过设计确认电子邮件但仍生成confirmmaton_token以允许我手动向添加的用户发送自定义确认电子邮件?

谢谢

见确认.rb 。 特别是,在253 – 256线附近。我认为这应该可以帮到你。

简而言之:

 module Devise module Models module Confirmable module ClassMethods # Generate a token checking if one does not already exist in the database. def confirmation_token generate_token(:confirmation_token) end end end end end 
 @user = User.new(:email => 'email@example.com', :password => 'password') @user.skip_confirmation_notification! @user.save 

在这里skip_confirmation_notification! 生成确认令牌但不发送确认电子邮件。