2016-03-21 15 views
0

Onların github docs aşağıdaki şebek mücevher kullanmaya çalışıyorum ve duyuyorum. İşte kod ben olduğunu @ durum 400 ile yanıtGibbon :: MailChimpError (sunucu title = "Geçersiz Kaynak"

class ChimpController < ApplicationController 
    def create 
    send_to_mail_chimp (params[:email]) 
    end 

    def send_to_mail_chimp(email) 
    puts "send email is #{email}" 
    gibbon = Gibbon::Request.new(api_key: "bla") 
    gibbon.timeout = 10 
    gibbon.lists('e61cf2454d').members.create(body: {email_address: email, status: "subscribed"}) 
    end 
end 


<%= simple_form_for :email, url: newsletter_path, :method => :post do |f| %> <%= f.input :email, input_html: {class: 'form-control', placeholder: 'enter email'} %> <% end %>

tam hata mesajıdır

Gibbon::MailChimpError (the server responded with status 400 @title="Invalid Resource", @detail="The resource submitted could not be validated. For field-specific details, see the 'errors' array.", @body={"type"=>"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/", "title"=>"Invalid Resource", "status"=>400, "detail"=>"The resource submitted could not be validated. For field-specific details, see the 'errors' array.", "instance"=>"", "errors"=>[{"field"=>"email_address", "message"=>"Schema describes string, object found instead"}]}, @raw_body="{\"type\":\"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/\",\"title\":\"Invalid Resource\",\"status\":400,\"detail\":\"The resource submitted could not be validated. For field-specific details, see the 'errors' array.\",\"instance\":\"\",\"errors\":[{\"field\":\"email_address\",\"message\":\"Schema describes string, object found instead\"}]}", @status_code=400): 
    app/controllers/chimp_controller.rb:10:in `send_to_mail_chimp' 
    app/controllers/chimp_controller.rb:3:in `create' 

cevap

2

deneyin geri alıyoruz hata mesajı mı söylüyor sorunun tam olarak ne: Bunun yerine bir javascript nesne (yakut karma) olarak e-postayı geçiyoruz

{ 
    "field": "email_address", 
    "message": "Schema describes string, object found instead" 
} 

dize. Geçmeniz gereken tek şey ham e-posta adresi.

1

members yöntemini küçük harfli e-posta adresinin bir MD5 hash değerini (via the mailchimp subscriber management) vermeniz gerektiğini düşünüyorum.

def send_to_mail_chimp(email) 
    puts "send email is #{email}" 
    gibbon = Gibbon::Request.new(api_key: "bla") 
    gibbon.timeout = 10 
    md5_email = Digest::MD5.hexdigest(email['email'].downcase) 
    # I prefer 'upsert' to 'create' but should work with either 
    gibbon.lists('e61cf2454d').members(md5_email).upsert(body: {email_address: email['email'], status: "subscribed"}) 
end 
+0

{"email" => "[email protected]" için undefined yöntemi 'downcase '}: ActionController :: Parametreler – gates

+0

Herhangi bir nedenden dolayı, parametreniz bir dizgi değil karma gibi geliyor. – SomeSchmo

+0

düzeltilmelidir Bu aynı zamanda ilk hatayı neden olabilirdi – SomeSchmo

İlgili konular