2016-03-29 13 views
1

私はRuby 1.9.3を使用しており、SendGrid APIを使用しようとしているときに次の行に次のエラーが表示されます。NoMethodError Ruby 1.9.3

NoMethodError (undefined method `to_h' for #<Hash:0x00000005da0958>): 

CODE:[ "mailer.mail(mail_defaults)" 以下、このライン上]

ERROR

と仮定し、一部のユーザー

 recipients = [] 

     recipient = SendGrid::Recipient.new('[email protected]') 
     recipient.add_substitution('name', 'Billy Bob') 
     recipient.add_substitution('number', 1234) 
     recipient.add_substitution('time', '10:30pm') 

     recipients << recipient 



     # then initialize a template 
     template = SendGrid::Template.new('blahblah7bef2-d25b00') 

     # create the client 
     # see client above 

     # set some defaults 
     mail_defaults = { 
     :from => '[email protected]', 
     :html => '<h1>I like email tests</h1>', 
     :text => 'I like email tests', 
     :subject =>'Test Email is great', 
     } 

     mailer = SendGrid::TemplateMailer.new(client, template, recipients) 

     # then mail the whole thing at once 
     mailer.mail(mail_defaults) 

は、私はこれを試してみましたので、それは私のmail_defaults配列かもしれないと思いました(下記参照)、同じ行に同じエラーが発生しました。

mail_defaults = { 
     from: '[email protected]', 
     html: '<h1>I like email tests</h1>', 
     text: 'I like email tests', 
     subject: 'Test Email is great', 
     } 

私のコードに誤りがありますか?それともSendGrids mailer.mailメソッドにエラーがありますか?

+0

あなたは私たちに、完全なバックトレースを表示していただけますか? 'config/initializers/backtrace_silencers.rb'でbacktraceサイレンサーを削除する必要があるかもしれません。 – BoraMa

答えて

0

この問題はmail.mailerにあります。これはRuby 2.1で実装されたto_hメソッドを内部的に使用します。効果的に、sendgrid sdkには今やruby 2.1が必要です。 Ruby 1.9.3で同じ問題が発生し、2.1にアップグレードして解決しました。

これは、私はCentOSの6(ない私の要旨)上のRuby 2.1にアップグレードするために使用するものである: https://gist.github.com/mustafaturan/8290150

は、この情報がお役に立てば幸いです。

関連する問題