Shilpi Agrawal
Shilpi Agrawal

Reputation: 615

Skip confirmation mail in devise

I want to skip the sending of confirmation mail from devise in my rails 4 application. I tried so many things, but none of them worked.

In my user.rb

before_create :my_method

def my_method
    self.skip_confirmation
end

I tried this also

before_create :my_method

def my_method
    !confirmed
end

I tried removing :confirmable from user.rb but none of them seems to work. Thanks in advance :)

Upvotes: 2

Views: 2248

Answers (4)

Artur INTECH
Artur INTECH

Reputation: 7276

For every User instance:

class User < ApplicationRecord
  after_initialize do |user|
    user.skip_confirmation_notification!
  end
end

For some particular instance:

john = User.new
john.skip_confirmation_notification!

P.S. The answers above are about disabling the confirmation process entirely, whereas the author asked about disabling just sending an email.

Upvotes: 1

JohnPaul
JohnPaul

Reputation: 710

Try this

@user = User.new(:email => '[email protected]', :password => 'password') 
@user.skip_confirmation_notification!
@user.save

skip_confirmation_notification! generate a confirmation token but does not send confirmation email.

Upvotes: 2

Shiva
Shiva

Reputation: 12514

Note: If you want to skip only on certain places

If you are calling User.create before skip_confirmation!, you need to call User.new and user.save.

 @user = User.new(:first_name => "John", :last_name => "Doe")
 @user.skip_confirmation!
 @user.confirm!
 @user.save

A/C to your way

before_create :my_method

def my_method
    self.skip_confirmation!
    self.confirm!
end

excluding the term confirmable in devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable should skip in a whole

Upvotes: 5

dp7
dp7

Reputation: 6749

Try adding this to user.rb

protected

def confirmation_required?
 false
end

Upvotes: 1

Related Questions