Search code examples
ruby-on-railsapiemailmailchimpgibbon

Gibbon / Mailchimp Signup Form


Having some trouble creating a simple signup form for a mailchimp list. Can't figure out why when they email passes through, it doesn't pass over to mailchimp.. thoughts? I'm sure I missed a step here.

index.html.erb (Form)

<%= form_tag('/welcome/subscribe', method: "post", id: "subscribe",) do -%>
<%= email_field(:email, :address, {id: "email", placeholder: "email address"}) %>
<%= submit_tag("Join!") %>
<% end %>

Gibbon.rb (Initializer)

Gibbon::API.api_key = "Secret API Key"
Gibbon::API.timeout = 15
Gibbon::API.throws_exceptions = false

Welcome.rb (Model)

def subscribe

@list_id = "Secret List ID"
gb = Gibbon::API.new

gb.lists.subscribe({
  :id => @list_id,
  :email => {:email => params[:email][:address]}
  })
end

Routes.rb

Rails.application.routes.draw do
root 'welcome#index'
post 'welcome/subscribe' => 'welcome#subscribe'
end

Solution

  • Users are probably being added as pending, requiring them to opt-in to be fully subscribed. You'll want to pass the double_opt_in: false parameter to your subscribe call.