Newbie to Rails, Gibbon and Mailchimp API. My goal is to send the email addresses of new users to my Mailchimp list using Gibbon.
I'm using Devise for signup, and I figured I could just attach the Gibbon.new class into the User.create controller. I am able to send an email address to Mailchimp subscribe through Gibbon in the rails console, but it doesn't work in my dev environment fired from the controller. Any idea what's (not) going on?
Users controller:
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
# Tell the UserMailer to send a welcome Email after save
UserMailer.welcome_email(@user).deliver
# Add the new user email to Mailchimp
gb = Gibbon.new(ENV['MAILCHIMP_API_KEY'])
gb.list_subscribe(:id => ENV['MAIL_CHIMP_DEFAULT_LIST_ID'], :email_address => @user.email)
format.html { redirect_to(@user, :notice => 'User was successfully created.') }
format.json { render :json => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.json { render :json => @user.errors, :status => :unprocessable_entity }
end
end
end
Gemfile:
gem 'gibbon'
application.yml
MAILCHIMP_API_KEY: ENV['my-api-key']
MAIL_CHIMP_DEFAULT_LIST_ID: ENV['my-list-id']