Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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']
share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.