我正在尝试将MailChimp Api包含在rails中的带有Gibbon的电子邮件表单中。
添加邮件等操作,我在控制台中看到API的正确回调,但除了成功的情况外,它正确地更改了电子邮件id div,什么也没有发生。
似乎用例开关不起作用,或者它无法读取从api返回的代码。
路线等设置正确。
这是我的财务总监:
class MailchimpformController < ApplicationController
def index
end
def submit
mailchimp_api_key = "mysecretapikey"
mailchimp_list_id = "mysecretlistid"
g = Gibbon.new(mailchimp_api_key)
response = g.list_subscribe({:id => mailchimp_list_id,
:email_address => params[:email],
:double_optin => false,
:send_welcome => false})
if(response.is_a?(Hash))
puts response
case response['code']
when 502
@js_email_error = "Invalid Address!"
when 214
@js_email_error = "Already signed up!"
else
@js_email_error = response['error']
end
@js_email_success = nil
else
@js_email_success = "Thanks!"
@js_email_error = nil
end
respond_to do |format|
format.js
end
end
end
只有当它向列表中添加新的电子邮件时,它才能工作。
index.html.erb
<%= form_tag submit_path, :class=> "form", remote: true do %>
<%= text_field_tag :email, nil, :class => 'email', :type=>"email", :placeholder => 'Sign up for beta testing' %>
<%= submit_tag "Absenden", :alt => "Absenden", class: "input-btn"%>
<% end %>
和javascript的东西submit.js.erb
<% if @js_email_error %>
$("#email").val("<%= @js_email_error %>");
<% end %>
<% if @js_email_success %>
$("#email").val("<%= @js_email_success %>");
<% end %>
我还收到了POST /mailchimpform/submit的Completed 500 Internal Server Error
,其中包含来自MailChimp API的(正确)回调。我不知道为什么。
发布于 2013-03-07 14:04:09
好了,现在起作用了。此错误是由对长臂猿的错误处理(设置)引起的。
使用
g.throws_exceptions = false
在提交之前,它现在工作正常。
https://stackoverflow.com/questions/15229037
复制相似问题