Search

Email Marketing for your Rails App Made Easy With Mailchimp

Daniel Rice

2 min read

Oct 17, 2011

Email Marketing for your Rails App Made Easy With Mailchimp

So you’ve got an awesome web application up and running. You want to keep your users engaged. You could try to handle collecting emails, writing your own newsletters, managing the list, keeping content fresh, tracking who read your messages, and so on (and so on) – all within your own app; however, there’s a better way. We recommend using Mailchimp. It’s actually very simple to integrate Mailchimp into your own Ruby on Rails application. Quick. Easy. DRY. Just the way we like it.

At Highgroove, we’re notorious for not wanting to re-invent the wheel. We LOVE using plugins, open-source libraries, ruby gems, and other external integrations in our apps. Mailchimp.com is one of those external services we regularly rely on.

A fairly common scenario is to collect user emails and send them a subscriber newsletter. We need all the basics: collect the email itself, ensure the email is real, send the actual newsletter on a certain schedule, and allow users to opt-out or change their email profile settings.

The first step to completing this online subscriber newsletter is to signup for Mailchimp.com. Once that is done, provide your API Key to us.

The second step is to create a List within Mailchimp. This List could be called “My Sites Newsletter”, for example.

The third step is to install the Gibbon gem. This is essentially a Ruby wrapper for Mailchimp.com’s own API.

Now that we’ve taken care of all the setup of Mailchimp, the next couple of steps will show you just how amazing Mailchimp.com and Gibbon really are:

On a basic level, all we need in the Rails application’s code is an HTML form that collects an email address and some code within a controller method to save the submitted email address to Mailchimp. We do this in two steps:

First, create your form (this example is a HAML template):

Two, in your controller, add a line like this:

Once you’ve done the above, your Rails app is fully integrated with Mailchimp! The content, frequency, and other settings that have to do with your newsletter are all controlled in Mailchimp’s very simple interface.

The only question you’ll have left at this point is “What cool feature can we add next?”

Mark Dalrymple

Reviewer Big Nerd Ranch

MarkD is a long-time Unix and Mac developer, having worked at AOL, Google, and several start-ups over the years.  He’s the author of Advanced Mac OS X Programming: The Big Nerd Ranch Guide, over 100 blog posts for Big Nerd Ranch, and an occasional speaker at conferences. Believing in the power of community, he’s a co-founder of CocoaHeads, an international Mac and iPhone meetup, and runs the Pittsburgh PA chapter. In his spare time, he plays orchestral and swing band music.

Speak with a Nerd

Schedule a call today! Our team of Nerds are ready to help

Let's Talk

Related Posts

We are ready to discuss your needs.

Not applicable? Click here to schedule a call.

Stay in Touch WITH Big Nerd Ranch News