Ruby on rails Mailchimp gem double_optin false不工作
双重选择确认邮件仍然会通过,你知道怎么了吗?由于长臂猿宝石有问题,所以选择了mailchimp宝石 GemfileRuby on rails Mailchimp gem double_optin false不工作,ruby-on-rails,ruby-on-rails-4,mailchimp,Ruby On Rails,Ruby On Rails 4,Mailchimp,双重选择确认邮件仍然会通过,你知道怎么了吗?由于长臂猿宝石有问题,所以选择了mailchimp宝石 Gemfile gem "mailchimp-api", "~> 2.0.4" 应用程序\u controller.rb class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want t
gem "mailchimp-api", "~> 2.0.4"
应用程序\u 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
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
从
订阅(id,email,merge\u vars=nil,email\u type=html,double\u optin=true,update\u existing=false,replace\u interests=true,send\u welcome=false)⇒ 散列
double_optin
是将直接传递的参数,与您所做的不同
因此,它将是:
@mc.lists.subscribe(@list_id, email, nil, 'html', false)
上面的答案不断给我错误,这对我很有用:
@mc.lists.subscribe(@list_id, { "email" => email }, merge_vars = nil, email_type = 'html', double_optin = false)
有了这些,我现在收到了我试图提交的任何电子邮件的前消息错误
rescue Mailchimp::Error=>ex if ex.message respond_to do | format | format.json{render:json=>{:message=>“出现错误。请输入有效的电子邮件id.“}}}}end
尝试解释此答案与上述答案的不同之处。作为对另一个答案的评论,这可能更好。
@mc.lists.subscribe(@list_id, email, nil, 'html', false)
@mc.lists.subscribe(@list_id, { "email" => email }, merge_vars = nil, email_type = 'html', double_optin = false)