JohnOHFS
JohnOHFS

Reputation: 174

Rails Mailchimp Background Job Not Implemented Error

So I'd like to add a user that registers on my rails site onto a mailing list. I've got the gibbon gem installed and I had success testing my ruby method in a stand-alone ruby file. I'm having issues integrating it into my application, however.

The error I receive in my rails logs is ERROR -- : NotImplementedError (NotImplementedError)

Here's my approach, which I tried to follow from this blog post: http://aspiringwebdev.com/mailchimp-and-active-job-on-rails-4-adding-users-to-your-mailing-list-in-the-background/

I have a background worker installed (sucker_punch).

I created a Job called AddUserToRegistrationListJob

class AddUserToRegistrationListJob < ActiveJob::Base
  queue_as :default
  require 'gibbon'

    def registration_list(user_id)
        user = User.find(user_id)
        email = user.email
        first_name = user.first_name
        last_name = user.last_name

        mailchimp_list_id = "my list id here"
        Gibbon::Request.api_key = "my api key here"
        Gibbon::Request.timeout = 15
        gibbon = Gibbon::Request.new

        gibbon.lists("#{mailchimp_list_id}").members.create(
            body: 
            {
                email_address: email, 
                status: "subscribed", 
                merge_fields: {FNAME: first_name, LNAME: last_name
                    }})
    end
end

Then in my user.rb file, I have

after_create :add_user_to_registration_list

def add_user_to_registration_list
    AddUserToRegistrationListJob.perform_later(self)
end

In my ruby file, which worked fine, I specified the argument for the method as

def registration_list(email, first_name, last_name)

and passed in the object when I ran the ruby file like this:

registration_list("[email protected]", "John", "Doe")

Wasn't clear on how to adjust the method or the arguments to accommodate rails. Any suggestions?

Upvotes: 0

Views: 227

Answers (0)

Related Questions