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

AnA*_*ice 5 ruby-on-rails devise ruby-on-rails-3

我正在使用

      user.skip_confirmation!
Run Code Online (Sandbox Code Playgroud)

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

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

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

谢谢

Sha*_*que 19

@user = User.new(:email => 'email@example.com', :password => 'password') 
@user.skip_confirmation_notification!
@user.save 
Run Code Online (Sandbox Code Playgroud)

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


Ben*_*Hao 2

请参阅confirmable.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
Run Code Online (Sandbox Code Playgroud)