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?
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
来源:https://stackoverflow.com/questions/10877475/rails-devise-sending-an-email-after-user-comfirms-registration