Disable Devise confirmable mails
Asked Answered
S

6

20

Recently I added the confirmable module to my User class. I already have a quite nice mailing system (Sidekiq, Sendgrid...) in my app, so I created my own "confirm account" mail. The problem now is to disable Devise from sending its default email. Is there any way to completely disable the Devise mailing system?

Added:

  • I want to maintain the confirmable module, as I am using its attributes and routes.
  • I can't use skip_confirmation! because I want the users to confirm their account.
  • I just want to disable Devise mails.
Storehouse answered 23/11, 2012 at 14:58 Comment(0)
T
44

Use the source, Luke:

# lib/devise/models/confirmable.rb

# A callback method used to deliver confirmation
# instructions on creation. This can be overriden
# in models to map to a nice sign up e-mail.
def send_on_create_confirmation_instructions
  send_devise_notification(:confirmation_instructions)
end

So override this method in your model to do nothing.

Tichonn answered 23/11, 2012 at 15:19 Comment(1)
Glad it helped. If you use bundler, you can always look at any gem's source easily with bundle open <gem> to take a look around.Tichonn
G
8

Try overriding the following devise method in your model:

def confirmation_required?
  !confirmed?
end

or use skip_confirmation!:

user = User.new(params) 
user.skip_confirmation! 
user.save! 
Gibber answered 23/11, 2012 at 15:22 Comment(1)
This is helpful when importing seed data.Enslave
D
7

Use skip_confirmation! method before saving any object.

def create
  @user = User.new(params[:user])
  @user.skip_confirmation!
  @user.save!
end
Doorplate answered 23/11, 2012 at 15:14 Comment(4)
I don't want to skip the confirmation. I just want Devise not to send its email, as I am sending my own.Storehouse
@CristianPlanasGonzález skip_confirmation! will only skip devise confirmation method not your own confirmation method. Please try this it will work.Doorplate
skip_confirmation! sets the confirmed_at attribute to Time.now, basically confirming the user. I'm using all the Devise confirmable module, except the mail.Storehouse
You should use skip_confirmation_notification!.Pokeweed
P
2

I think just removing

:confirmable

from the user model should do it

or have you tried disabling

config/environments/development.rb

config.action_mailer.default_url_options = { :host => 'localhost:3000' }
Pedersen answered 23/11, 2012 at 14:59 Comment(2)
I need the confirmable module because I am confirming users. I use the confirm routes that devise provides to me, and also the confirmable attributes of the User class. I just don't want Devise to send a mail, as I want to send my own.Storehouse
ah right i see, couldnt you just modify the devise mailer to look how you want it too, seems an effort to not use the built in features?Pedersen
D
2

I recommend you

User.skip_reconfirmation!

That is skip confirm mail and update email not to use "confirm!"

Dermott answered 4/11, 2015 at 5:54 Comment(0)
D
0

remove (:confirmable) from devise model ex:- here my devise model is User here I used like this.

class User < ActiveRecord::Base  
     devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,:omniauthable

end
Danyel answered 16/3, 2016 at 11:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.