本文介绍了Mailchimp gem double_optin false无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
双重选择加入确认电子邮件仍在进行中,您知道这是怎么回事吗?长臂猿宝石有问题,因此选择了mailchimp宝石.
double opt-in confirmation email still goes through, any idea what's wrong? Was having problems with the gibbon gem, so opted for mailchimp gem instead.
宝石文件
gem "mailchimp-api", "~> 2.0.4"
application_controller.rb
application_controller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :setup_mcapi
def setup_mcapi
@mc = Mailchimp::API.new('mailchimp api key goes here')
@list_id = "list id goes here"
end
end
welcome_controller.rb
welcome_controller.rb
class WelcomeController < ApplicationController
def index
end
def subscribe
email = params[:email][:address]
if !email.blank?
begin
@mc.lists.subscribe(@list_id, {'email' => email}, 'double_optin' => false)
end
respond_to do |format|
format.json{render :json => {:message => "Success!"}}
end
rescue Mailchimp::ListAlreadySubscribedError
respond_to do |format|
format.json{render :json => {:message => "#{email} is already subscribed to the list"}}
end
rescue Mailchimp::ListDoesNotExistError
respond_to do |format|
format.json{render :json => {:message => "The list could not be found."}}
end
rescue Mailchimp::Error => ex
if ex.message
respond_to do |format|
format.json{render :json => {:message => "There is an error. Please enter valid email id."}}
end
else
respond_to do |format|
format.json{render :json => {:message => "An unknown error occurred."}}
end
end
end
else
respond_to do |format|
format.json{render :json => {:message => "Email Address Cannot be blank. Please enter valid email id."}}
end
end
end
end
index.html.erb
index.html.erb
<h3>Add a New Member</h3>
<p>Please enter your email address to subscribe to our newsletter.</p>
<%= form_tag('/welcome/subscribe', method: "post", id: "welcome", remote: "true") do -%>
<%= email_field(:email, :address, {id: "email", placeholder: "email address"}) %>
<%= submit_tag("Subscribe") %>
<% end %>
<div id="response">Response Will be displayed here</div>
routes.rb
routes.rb
Rails.application.routes.draw do
root 'welcome#index'
post 'welcome/subscribe' => 'welcome#subscribe'
end
推荐答案
double_optin
是将直接传递的参数,与您的操作不同.
The double_optin
is the parameter which will be passed directly not like what you did.
因此,它将是:
@mc.lists.subscribe(@list_id, email, nil, 'html', false)
这篇关于Mailchimp gem double_optin false无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!