Rails:设计:在用户确认注册后发送电子邮件

时间:2012-06-04 07:01:43

标签: ruby-on-rails devise devise-confirmable

我的应用程序正在使用Devise,正在发送确认电子邮件,并在用户点击确认链接后正确确认用户。我还希望在用户确认后发送第二封电子邮件。

关于如何延迟确认或两步确认,有很多建议,但没有关于我正在寻找什么(我能找到)。

Devise :: Module :: Confirmable文档告诉我使用的方法是确认!,但我不知道如何做到这一点。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

Rails Devise: after_confirmation

只需定义一个after_save回调,检查用户是否已确认,如果是,则发送电子邮件。

如果要保存几个CPU周期,可以使用以下内容覆盖Devise ConfirmationsController:

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
相关问题