I am trying to make it so that if a one type of User is created - then instead of sending the confirmations email, it sends the reset password link (I have already achieved so that the reset password link serves as both confirmation and reset password). This is basically a try to avoid duplication of emails since I allow creating a user without password so that the user then can request his first password via reset password.
I am trying to override the Confirmations Controller like so:
class Users::ConfirmationsController < Devise::ConfirmationsController
def create
if self.resource.encrypted_password.empty? then
Users::PasswordsController.create
else
super
end
end
end
And in routes:
devise_for :users, controllers: {
passwords: 'users/passwords',
sessions: 'users/sessions',
confirmations: 'users/confirmations',
omniauth_callbacks: 'omniauth_callbacks'
}
The overriding works with other models. But the create action in confirmations controller is never called. I put a lot of byebug
statements all around the Gem itself, and it seems even the original create action is not called, but the email is sent anyway. I am using sidekiq
for delayed emails. The only place that is run seems to the mailer:
def confirmation_instructions(record, token, opts={})
byebug # <- it does stop here
@token = token
devise_mail(record, :confirmation_instructions, opts)
end
But when I check the stack trace, it looks like it's called from some labda function.
The question: why isn't devise using ConfirmationsController
and how do I achieve the task at hand?
Thanks a lot!