Skip to content

Instantly share code, notes, and snippets.

@ankane
Created April 5, 2019 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankane/471a6b32183ae3d6c7595f0589273802 to your computer and use it in GitHub Desktop.
Save ankane/471a6b32183ae3d6c7595f0589273802 to your computer and use it in GitHub Desktop.

Devise email change notifications with encrypted attributes in Rails 5.2

Add to the Devise initializer:

config.send_email_changed_notification = true

Use this PR for attr_encrypted

gem 'attr_encrypted', github: 'Countable-us/attr_encrypted', branch: 'active-record-5.2'

Add this to your model

class User < ApplicationRecord
  def send_email_changed_notification
    send_devise_notification(:email_changed, to: email_was)
  end
end
@nick453
Copy link

nick453 commented May 8, 2019

Thank you very much for your precious help.
I set config.send_email_changed_notification = true and follow all the steps!
But I still get the error: " ArgumentError: SMTP To address may not be blank"
I think because of "Confirmable" Devise module. When I try to change the email, the new email is set on 'unconfirmed_email' field and the "encrypted_email" field is set to blank (this cause the error IMHO). Just when the new email is confirmed, the "encrypted_mail" is filled with the new email.
Thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment