2016-03-21 13 views
0

私は彼らのgithubのドキュメント以下のテナガザルの宝石を使用しようとしています。ここでは、コード、私が持っている@ステータス400で応答しギボン:: MailChimpErrorは(サーバは、タイトル=「無効なリソース」

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 %>

正確なエラー・メッセージがある

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' 

答えて

2

をお試しください文字列。あなたが渡す必要があるのは生の電子メールアドレスだけです。

1

membersメソッドに小文字のメールアドレス(via the mailchimp subscriber management)のMD5ハッシュを付ける必要があると思います。

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

あなたはjavascriptオブジェクト(ルビーハッシュ)の代わりとしてで電子メールを渡している:あなたが戻って取得しているエラーメッセージは、問題がある正確に何を言っている

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]"}のための未定義メソッド 'downcase ':ActionController :: Parameters – gates

+0

何らかの理由でパラメータが文字列ではなくハッシュとして渡ります。修正する必要があります – SomeSchmo

+0

これはまた、あなたの初期エラーの原因となる可能性があります – SomeSchmo

関連する問題