Devise: Is it possible to NOT send a confirmation email in specific cases ?

1.3k views Asked by At

Actually I am using devise for login and registration and its working fine, it send a confirmation email which is really good. But I need to send confirmation email in specific cases. I am passing user type in URL and on behalf of that I want to set mail. I have two type of users, one will be confirm their account their self reset of the users can not confirm their account only admin can approve their accounts. I have override the create method

def create
    super
    if params[:type]=='xyz
        @user.skip_confirmation_notification!
    end
end

but it sends mail in both cases. Please tell where am wrong.

1

There are 1 answers

0
Rubyrider On BEST ANSWER

So according to devise confirmable module you can skip to send confirmation and email by following code.

 def confirm_your_type_user_without_confirmation_email
     # check your condition here and process the following
     self.skip_confirmation! 
     self.confirm!
     # condition may end here
 end

Now lets call it on create hook.

class User < ActiveRecord::Base
  after_create :confirm_your_type_user_without_confirmation_email
  ....
end

for more reference you may check this: Devise Confirmable module

The solution should be something similar as I mentioned here above. And its best practice to avoid controller to handle these responsibilities, because its not something your controller should take. :) I hope my answer will give you some way to solve your problems! Thanks!