1

I'm trying to add email confirmation to a model called "Project" in a Rails app: users should be able to set an email address for a project, which is not saved until they click a confirmation link sent to the email address provided.

Although I have no need for its authentication features, I thought the Devise gem might be useful. I was hoping to use :reconfirmable to implement the feature: when the user tries to save an email to the project, it instead is saved to the unconfirmed_email column until they confirm.

It appears, partly, to be working -- the database is updated correctly, a token is generated, the "confirmation_sent_at" field is set. But no email template is rendered (and no email is sent). Looking at the code path in lib/devise/models.rb I can see how, before the email field is saved to, a method is called that intercepts that save and instead saves to unconfirmed_email. But where is the email send actually triggered? What do I have to do to activate it?

Alex Lew
  • 2,064
  • 14
  • 17

1 Answers1

1

Assuming that you have correctly configured Devise to use the :confirmable feature and configured your email properly (as described in this answer). Then it should be as simple as calling this:

user.send_confirmation_instructions # where user is one of your Devise users

At the very least, making the send_confirmation_instructions call should show that the email is sending in the Rails log. If that is the case but you don't ever receive an email then you have your email configured incorrectly.

Community
  • 1
  • 1
Mike S
  • 11,329
  • 6
  • 41
  • 76
  • Thanks! I put this in the controller create and update methods, and it worked. The documentation says send_confirmation_instructions triggers an email "manually" -- do they ever automatically trigger, or only when I call this method? – Alex Lew Jun 03 '15 at 17:49
  • Yes I've definitely had Devise trigger the email automatically many times. I wonder if it **only** does it automatically upon the initial creation of the record? Updates may not trigger it. – Mike S Jun 03 '15 at 17:53