Sending Mandrill Merge Variables using Rails Controller

Last Updated: February 07, 2018

Sending Mandrill Merge Variables using Rails Controller

I was having a heck of a time getting my Mandrill merge variables to get passed to the MailChimp template that I’m using in my Mandrill account. That’s right, by connecting your Mandrill and MailChimp accounts, you can create sexy email templates in MailChimp and use them in Mandrill for transactional emails.

For the longest time, I was following the Mandrill directions verbatim, I was formatting it just like mandrill wanted:

Their example(without headers method from Rails):

X-MC-MergeVars: {“var1": “global value 1"}


headers[X-MC-MergeVars] = {“name” =>”Patty Jones”, “message” =>”What's up good sir?”}

For some reason, this was not passing my variables to Mandrill. Well, it turns out you need to convert your merge variables to a JSON object before you send it to Mandrill. The below worked perfectly! It passed my variables to my email template.

So, you know what that means, it’s time to create some sexy “Welcome New User” email templates.