2016-03-29 18 views
1

SendGrid API'sini kullanmaya çalışırken Ruby 1.9.3 ve aşağıdaki satırı takip ederek aşağıdaki hatayı alıyorum.NoMethodError Ruby 1.9.3

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

KOD: [ "mailer.mail(mail_defaults)" Aşağıda bu satırda]

HATA

varsayarak bazı kullanıcılar

 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) 

ben bunu denedim bu yüzden benim mail_defaults dizisi olabileceğini düşündüm (aşağıya bakınız) ve aynı satırda aynı hatayı aldık.

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

benim kodunda bir hata varsa veya SendGrids mailer.mail yönteminde bir hata onların mı?

+0

Bize tam geri izleme gösterebilir misiniz? Backtrace susturucularını 'config/initializers/backtrace_silencers.rb' içinde kaldırmanız gerekebilir. – BoraMa

cevap

0

Bu sorun mail.mailer ile yapılmıştır. Bu, Ruby 2.1'de uygulanan to_h yöntemini dahili olarak kullanır. Etkin olarak, sendgrid sdk şimdi ruby ​​2,1 gerektirir. Ruby 1.9.3 ile aynı sorunu yaşadım ve 2.1'e yükselterek çözdüm. Bu yardımcı olur https://gist.github.com/mustafaturan/8290150

Hope: Bu benim CentOS 6 (benim özü) üzerine Ruby 2.1 yükseltmek için kullanılan budur

.

İlgili konular