Rails devise sending emails to wrong email address -
i installed devise in rails app , user registration works perfect. i've set such users can confirm accounts sending email. works fine when user signs first time (they confirmation message confirmation link).
however, when user changes his/her email address exampleuser@gmail.com
exampleuser@hotmail.com
, mail gets delivered exampleuser@gmail.com
, confirmation link has no confirmation token looks like
http://{host}/users/confirmation
instead of normal
http://{host}/users/confirmation?confirmation_token=token_here
when resave new email exampleuser@hotmail.com
gets delivered address confirmation token invalid not match 1 in db.
i don't know went wrong.
confirmation_instructions.html.erb
<p>welcome <%= @resource.unconfirmed_email? ? @resource.unconfirmed_email : @resource.email %>!</p> <p>you can confirm account email through link below:</p> <p><%= link_to 'confirm account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
i have config.reconfirmable = true
in devise initializer
am using sideqik delayed jobs. emails processed sideqik
any help? thanks
i realise sometime since posted, have run same issue , resolved it.
in case had upgraded devise v2.0.4 v2.2.6 - appears newest version supports rails 3.
i'd skimmed change log mentions change in v2.2.0:
all mailer methods expect second argument delivery options.
unfortunately doesn't second argument used for; turns out literally you'd expect... options hash passed mailers mail
method.
i'm guessing if you're me, previous devise::mailer had line following:
def confirmation_instructions(record, opts) mail :to => record.email, :template_name => 'confirmation_instructions' end
the problem email previous confirmed email address, not new unconfirmed one. hence want call mail options hash passed, contain unconfirmed_email in :to
key, e.g.
{:to => "unconfirmed@email.com"}
so change mail calls more like:
def confirmation_instructions(record, opts) mail opts.merge(:template_name => 'confirmation_instructions') end
Comments
Post a Comment