我正在使用 Ruby 1.9.3 并在尝试使用 SendGrid API 时在下一行收到以下错误。
错误[在“ mailer.mail(mail_defaults)
”下面的这一行]:
NoMethodError (undefined method `to_h' for #<Hash:0x00000005da0958>):
代码:
假设一些用户
recipients = []
recipient = SendGrid::Recipient.new('jn@geo.com')
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 => 'no-reply@geo.com',
: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: 'no-reply@geo.com',
html: '<h1>I like email tests</h1>',
text: 'I like email tests',
subject: 'Test Email is great',
}
我的代码有错误还是 SendGrids mailer.mail 方法有错误?