5

My application is using Devise, and is sending out confirmation emails properly, and confirming users properly as well after they click on the confirmation link. I would also like to send a second email AFTER the user is confirmed.

There is a lot of advice on how to delay confirmation, or 2-step confirmation, but nothing on what I'm looking for (that I can find).

The Devise::Module::Confirmable documentation tells me that the method to use is confirm!, but I am not sure how to do this. Any ideas?

EastsideDev
  • 6,257
  • 9
  • 59
  • 116

1 Answers1

4

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
Community
  • 1
  • 1
rpedroso
  • 985
  • 6
  • 10
  • I added devise_for :users, :controllers => { :registrations => 'registrations', :confirmations => 'confirmations' } to routes.rb. I am getting the following error message though: uninitialized constant Devise::ConfirmationController – EastsideDev Jun 04 '12 at 12:40
  • I also did see http://stackoverflow.com/questions/4558463/rails-devise-after-confirmation when I researched the issue, but it was not clear to me where the before_save callback should go. – EastsideDev Jun 04 '12 at 12:42
  • the problem was in the code I cut and paste. It should be Devise::ConfirmationsController – EastsideDev Jun 04 '12 at 20:17
  • I did indeed mistype Devise::ConfirmationsController. I have updated my answer with the correct code. – rpedroso Jun 04 '12 at 20:44
  • Thanks. I have been trying to mark this as answered, but the system will not allow me. I have another related question that I will post as a separate question. – EastsideDev Jun 04 '12 at 21:16