Created
September 19, 2012 12:22
-
-
Save andrewzimmer906/3749366 to your computer and use it in GitHub Desktop.
MailChimp Integration using Gibbon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- > 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 %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
This is using Ruby on Rails v 3.2.2 with the Gibbon and Thin Gem. Should be straightforward, you can definitely get fancier!