Rails: Devise: Sending an email after user comfirms registration

家住魔仙堡 提交于 2019-12-04 10:49:41
rpedroso

Rails Devise: after_confirmation

Simply define an after_save callback that checks to see if a user was confirmed, and if so, sends the email.

If you want to save a few CPU cycles, you could override the Devise ConfirmationsController with something like this:

class ConfirmationsController < Devise::ConfirmationsController

    def show
        self.resource = resource_class.confirm_by_token(params[:confirmation_token])

        if resource.errors.empty?
            set_flash_message(:notice, :confirmed) if is_navigational_format?
            sign_in(resource_name, resource)

            # Send the user a second email          
            send_post_confirmation_email

            respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
        else
            respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
        end
    end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!