LoginSignup
44
37

More than 5 years have passed since last update.

deviseでconfirmable設定をした際の確認メールをスキップさせる skip_confirmation! は、対象のオブジェクトをsaveする前に書く

Posted at

deviseでconfirmable設定をした際に、メアドのactivationメール(確認メール)の送信をスキップさせる方法のメモ。

obj.skip_confirmation!

↑の様に書けばスキップします。

skip_confirmation!を指定するタイミング

@user.saveのタイミングで(UserモデルをDeviseの管理対象にしている場合)、メールが送信される様です。

なので、skip_confirmation!は@user.saveの前に書きます。
new〜saveの間ですかね。

user = User.new(:username => data.name,
                :email => data.email,
                :password =>    Devise.friendly_token[0,20]
                )
user.skip_confirmation!
user.save

こんな流れになるかと思います。

class Users::RegistrationsController < Devise::RegistrationsController

  def create
    @user = User.new(sign_up_params)
    @user.skip_confirmation!
    if @user.save
      #@user.skip_confirmation! #not moved
    end
  end

References

44
37
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
44
37