0

I successfully installed devise in my rails app and the user registration works perfect. I've also set it up such that users can confirm their accounts by sending an email. This works fine when the user signs up for the first time (They get the confirmation message with a confirmation link).

However, when the user changes his/her email address from exampleuser@gmail.com to exampleuser@hotmail.com, the mail gets delivered to exampleuser@gmail.com and the confirmation link has no confirmation token it looks like

http://{HOST}/users/confirmation

Instead of the normal

http://{HOST}/users/confirmation?confirmation_token=TOKEN_HERE

When I resave the new email exampleuser@hotmail.com it now gets delivered to this address but the confirmation token is invalid as it does not match the one in the db.

I don't know what went wrong.

confirmation_instructions.html.erb

<p>Welcome <%= @resource.unconfirmed_email? ? @resource.unconfirmed_email : @resource.email %>!</p>

<p>You can confirm your account email through the link below:</p>

<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>

I also have config.reconfirmable = true in devise initializer

Am also using sideqik for delayed jobs. The emails are all processed by sideqik

Any help? Thanks

Joseph N.
  • 2,437
  • 1
  • 25
  • 31

1 Answers1

0

I realise it is sometime since you posted, but I have run into this same issue and resolved it.

In my case I had upgraded devise from v2.0.4 to v2.2.6 - which appears to be the newest version that supports Rails 3.

I'd skimmed the change log which mentions this change in v2.2.0:

All mailer methods now expect a second argument with delivery options.

Unfortunately it doesn't say what that second argument is specifically used for; however it turns out is literally what you'd expect... The options hash that is passed to your Mailers mail method.

I'm guessing if you're like me, your previous Devise::Mailer had a line something like the following:

  def confirmation_instructions(record, opts)
    mail :to => record.email, :template_name => 'confirmation_instructions'
  end

The problem is that email is the previous confirmed email address, not the new unconfirmed one. Hence you probably want to call mail with the options hash you were passed, which will now contain the unconfirmed_email in its :to key, e.g.

  {:to => "unconfirmed@email.com"}

So simply change your mail calls to something more like:

  def confirmation_instructions(record, opts)
     mail opts.merge(:template_name => 'confirmation_instructions')
  end
Rick Moynihan
  • 481
  • 3
  • 10