我正在尝试使用sendgrid-ruby API发送电子邮件。我有一个Attachment模型,用于跟踪AWS桶中上传的文件。
我只是尝试在设置后运行bundle安装
gem 'sendgrid-ruby' 在我的Gemfile中,但是在安装gem之后加载应用程序时,我会得到以下错误:
TypeError (superclass mismatch for class Attachment):
app/models/attachment.rb:1:in `<top (required)>'
app/controllers/jobs_controller.rb:182:in `edit'不管怎么说,在不更改我的模型名称的情况下,是否可以修复这个问题?
更新:
我的SendGridEmail课程:
require 'sendgrid-ruby'
include SendGrid
class SendGridEmail
def initialize
end
def send_message
mail = Mail.new
mail.from = Email.new(email: 'test@example.com')
mail.subject = 'I\'m replacing the subject tag'
personalization = Personalization.new
personalization.add_to(Email.new(email: 'cannon.moyer@treadmilldoctor.com'))
personalization.add_substitution(Substitution.new(key: '-name-', value: 'Example User'))
personalization.add_substitution(Substitution.new(key: '-city-', value: 'Denver'))
mail.add_personalization(personalization)
mail.add_content(Content.new(type: 'text/html', value: 'I\'m replacing the <strong>body tag</strong>'))
mail.template_id = '7fd8c267-9a3c-4093-8989-3df163e87c47'
sg = SendGrid::API.new(api_key: "xxxxxxxxxxxxxxxxxxxxxx")
begin
response = sg.client.mail._("send").post(request_body: mail.to_json)
rescue Exception => e
puts e.message
end
puts response.status_code
puts response.body
puts response.headers
end
def create_notification
@customer.notifications.create(name: "Manually Text Job to Customer", to: "+1", notification_type: "Manual Job Notification")
end
end发布于 2018-05-29 18:19:51
使用include会扰乱名称空间,所以最好不要这样做。Ruby有一个独立的全局命名空间,与Python和Node不同,因此在导入时需要非常小心。
如果您的include SendGrid有一个SendGrid::Attachment类,那么SendGrid::Attachment将尝试与您的Attachment类进行协调,这将失败。
最好的计划是更新您的代码,以便在所有内容中都包含SendGrid::前缀。一个设计良好的库将被清晰的命名空间以避免这个问题。
https://stackoverflow.com/questions/50589869
复制相似问题