Search code examples
ruby-on-railsruby-on-rails-3deviseconfirmationdevise-confirmable

Devise: how to use another mail view when user requests email change ( instead of the default )


  1. Logged in user changes email under users#registration
  2. User receives email to confirm this email change

The email send in step 2 is exactly the same as when a user registers for the first time and has to confirm his email for the first time.

Is there a way to use another email view So I can more customise the text like "you requested your email to be changed, please click below link.. " instead of using the default message.

This would be a cosmetic but much wanted feature in our application.

Anyway to do this? Kind regards!


Solution

  • This is not trivial task, actualy you need to overwrite this devise method inside your model:

      def send_confirmation_instructions
        if reconfirmation_required?
          self.confirmation_token = nil if reconfirmation_required?
          @reconfirmation_required = false
    
          ensure_confirmation_token!
    
          opts = pending_reconfirmation? ? { :to => unconfirmed_email } : { }
          send_devise_notification(:reconfirmation_instructions, opts)
        else
          super
        end
      end
    

    Then you need to extend Devise::Mailer to add method reconfirmation_instructions

    And finally you need to create view app/views/devise/mailer/reconfirmation_instructions.html.erb