如何使用复选框向订阅者保存电子邮件? [英] How to save email to subscribers with checkbox?

查看:73
本文介绍了如何使用复选框向订阅者保存电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

选中此框后,如何在点击保存后将用户的电子邮件从输入电子邮件添加到我的mailchimp订阅者列表中?

When the box is checked how can I add the user's email from 'Enter Email' to my mailchimp subscribers list upon him clicking Save?

user / new.html.erb

<%= form_for(@user) do |f| %>
  <%= f.email_field :email, placeholder: 'Enter Email' %>
  <%= f.check_box ????? %> Get blog posts from Anthony Galli, CEO & Founder about conquering challenges in life & business!
<% end %>

在注册过程之外,人们可以通过 subscribes / subscribe.html输入他们的电子邮件进行订阅.erb

Outside of the signup process people can subscribe via inputting their email in subscribes/subscribe.html.erb.

<!-- MailChimp Signup Form -->
<link href="//cdn-images.mailchimp.com/embedcode/classic-081711.css" rel="stylesheet" type="text/css">
<div id="mc_embed_signup">
  <form action="//anthonygalli.us8.list-manage.com/subscribe/post?u=3e4b26579d28ecaf37fe444e4&amp;id=3dbb9c5c12" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <input type="email" value="" name="EMAIL" class="required email" placeholder="Enter Email" id="mce-EMAIL">
    <input type="text" name="b_3e4b26579d28ecaf37fe444e4_3dbb9c5c12" tabindex="-1" value="">
    <input type="submit" value="Save" name="subscribe" id="mc-embedded-subscribe" class="button">
  </form>
</div>
<script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script><script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';}(jQuery));var $mcj = jQuery.noConflict(true);</script>


推荐答案

表格已提交至您的应用程序。因此,您可以使用Mailchimp API将用户添加到列表中。有各种Mailchimp API宝石。我只选了一个:

The form is submitted to your App. So you can use the Mailchimp API to add the user to a list. There are various Mailchimp API gems. I just picked a random one:

点击这里查看如何设置API
https://github.com/amro/gibbon

Check here how to setup the API https://github.com/amro/gibbon

def create
  @user = User.new(user_params)
  if @user.save
    subscribe_to_newsletter(@user)
    redirect_to ...
  else
    ...
  end
end
private
def subscribe_to_newsletter(user)
  gibbon.lists(list_id).members.create(body: {email_address: user.email, status: "subscribed", merge_fields: {FNAME: user.first_name, LNAME: user.last_name}})
end

现在这可能需要一些时间。如果是这种情况,您可能希望将其移至后台作业。也许还将整个Mailchimp代码移动到服务对象,以便正确封装。

Now this might take some time. If this is the case you might want to move it to a background job. Perhaps also move the whole Mailchimp code to a service object so it is properly encapsulated.

这篇关于如何使用复选框向订阅者保存电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆