0

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!

Aurimas
  • 2,577
  • 5
  • 26
  • 37
  • 1
    Check out the Devise wiki: https://github.com/plataformatec/devise/wiki/How-To:-Email-only-sign-up and https://github.com/plataformatec/devise/wiki/How-To:-Override-confirmations-so-users-can-pick-their-own-passwords-as-part-of-confirmation-activation – Robin Oct 25 '16 at 12:44
  • Looks good, except that my solution should in theory be much simplier, only a few lines of code required. Do you know why the `create` action is not firing? – Aurimas Oct 26 '16 at 09:36

0 Answers0