Skip to content

Instantly share code, notes, and snippets.

@andrewzimmer906
Created September 19, 2012 12:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewzimmer906/3749366 to your computer and use it in GitHub Desktop.
Save andrewzimmer906/3749366 to your computer and use it in GitHub Desktop.
MailChimp Integration using Gibbon
# This is done on Rails 3.2.2
# Make sure to define your signup route in routes.rb as a POST
# Mailchimp
gem 'gibbon'
gem 'thin'
<!-- > under the views/welcome folder <-->
<%= form_tag signup_path, :class=> "form", remote: true do %>
<%= text_field_tag :email, nil, :class => 'email', :type=>"email", :placeholder => 'Sign up for beta testing' %>
<%= image_submit_tag "signupBtn.png", :alt => "Go", class: "input-btn"%>
<% end %>
//Under the views/welcome folder
<% if @js_email_error %>
$("#email").val("<%= @js_email_error %>");
<% end %>
<% if @js_email_success %>
$("#email").val("<%= @js_email_success %>");
$(".input-btn").attr("src", "/assets/checkbtn.png");
<% end %>
class WelcomeController < ApplicationController
def index
end
def signup
mailchimp_api_key = "xxx"
mailchimp_list_id = "xxx"
g = Gibbon.new(mailchimp_api_key)
response = g.listSubscribe({:id => mailchimp_list_id,
:email_address => params[:email],
:double_optin => false,
:send_welcome => true})
if(response.is_a?(Hash))
puts response
case response['code']
when 502
@js_email_error = "Invalid Address!"
when 214
@js_email_error = "Already signed up!"
else
@js_email_error = response['error']
end
@js_email_success = nil
else
@js_email_success = "Your email has been added!"
@js_email_error = nil
end
end
end
@andrewzimmer906
Copy link
Author

This is using Ruby on Rails v 3.2.2 with the Gibbon and Thin Gem. Should be straightforward, you can definitely get fancier!

@naxIO
Copy link

naxIO commented Feb 28, 2013

Hi! Thanks for posting this, but it seems not to work a 100%. It does the post to the API but the Javascript part wont work. In this code it would say "no view found" for signup. Is the thin gem required or would webbrick work as well? Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment