Rails Mailchimp Background Job Not Implemented Error

南笙酒味 提交于 2019-12-13 08:27:38

问题


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@example.com", "John", "Doe")

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

来源:https://stackoverflow.com/questions/39009488/rails-mailchimp-background-job-not-implemented-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!