我正在尝试从 Mailchimp 保存段 id 值。我成功创建了“订阅”和“取消订阅”流程。我现在尝试在每次创建“事件”模型时创建一个列表段(这允许我从我的电子邮件列表中创建一个侧段)。我可以创建列表段并获得返回给我的段 id 值,但我在保存该 id 时遇到问题。我的事件表中有一个 seg_id 列和一个 MailChimpList 模型类,我的所有方法都在其中调用 MailChimp api。
这是我在 MailChimpList api 中的方法
def event_segment_list(event)
event_mailer_id = @api.list_static_segment_add(
:name => event )
Rails.logger.info "Created segment for event #{event_mailer_id}"
end
记录器返回正确的值
现在我正在尝试将该值保存在我的事件类中,
class Event
after_create :create_email_segment
private
def create_email_segment
list = MailchimpList.new
if list.available?
id = list.event_segment_list(
self.slug
)
end
self.seg_id = id
end
end
将段 id 值保存在 seg_id 列中的最佳方法是什么?