自动将用户信息发送到Mailchimp

时间:2016-03-22 17:20:29

标签: ruby-on-rails devise mailchimp

在我的应用程序(设计)注册后,我需要做什么才能自动将用户的姓名和电子邮件发送到我的Mailchimp帐户?

2 个答案:

答案 0 :(得分:1)

你可能应该在创建钩子之后使用常规用户

class User < ActiveRecord::Base
  after_create :send_to_mailchimp

  def send_to_mailchimp
    # send data to mailchimp
  end
end

答案 1 :(得分:1)

我喜欢使用Gibbon,一个mailchimp包装器来处理他们的api

  def add_to_mailchimp(email_address, first_name, last_name)
    list_id = "your_list_id"
    gibbon = Gibbon::Request.new
    # only need the md5_email if you want to use 'upsert' (find_or_create_by) or 'update', not 'create'
    md5_email = Digest::MD5.hexdigest(email_address)

     gibbon.lists(list_id).members(md5_email).upsert(body: {email_address: email_address, status: "subscribed", merge_fields: {FNAME: first_name, LNAME: last_name}})
  end