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

南楼画角 提交于 2019-12-11 07:43:47

问题


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:


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!



来源:https://stackoverflow.com/questions/26986990/devise-is-it-possible-to-not-send-a-confirmation-email-in-specific-cases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!