Search code examples
ruby-on-railsdevisemandrilldevise-confirmableemail-confirmation

How to set Devise confirmable link on Mandrill template?


I know that with the Mandrill syntax that I can send in user specific info by doing something like this:

def confirmation_instructions(record, token, opts={})
  options = {
    :subject => 'Email confirmation',
    :email => record.email,
    :name => record.first_name,
    :global_merge_vars => [
      {
        name: 'email',
        content: record.email
      },
      {
        name: 'confirmation_link',
        content: record.confirmation_token
      }
    ],
    :template => 'confirm_email'
  }
  mandrill_send(options)
end

but how do I send the actual confirmation link that is in the devise confirmation instructions html.erb?

views/confirmable/mailer/confirmation_instructions.html.erb

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

UPDATE

I edited so I send this link:

content: 'http://localhost:3000/users/confirmation?confirmation_token=' + record.confirmation_token

It still doesn't work, I think because the token is actually encrypted. I'm thinking this is the case because when I use the default mailer the token is a lot shorter than the token I get from record.confirmation_token.

Can someone let me know how to pass the correct token to Mandrill?


Solution

  • I had the same issue, what worked for me was using 'token' instead of 'record.confirmation_token'. It seems that Devise's latests updates changed some Mailer's methods config.

    Instead of: http://domain.com/users/confirmation?confirmation_token=' + record.confirmation_token

    Use: http://domain.com/users/confirmation?confirmation_token=' + token

    Let me know if it helps you.