ROR:是什么导致未初始化的常量

时间:2019-05-06 14:03:28

标签: ruby-on-rails sendgrid sendgrid-api-v3

我必须从Sendgrid V2更新到V3。我正在使用Sendgrid-ruby gem 5.3。

我收到此错误

NameError (uninitialized constant PasswordController::Email):
app/controllers/password_controller.rb:54:in `send_email' 
May 06 08:57:01 burro-staging app/web.1: ArgumentError (wrong number of arguments (given 1, expected 0)):

这是引起问题的行(下面的第二行)。

  mail = SendGrid::Mail.new
  mail.from = Email.new(email: 'no-reply@getburro.com') <-----

1 个答案:

答案 0 :(得分:3)

Ruby正在寻找Email类,但找不到它。原因是因为Email属于Sendgrid模块,并且其作用域应如下所示:

Sendgrid::Email.new ...

如此处所示:

https://github.com/sendgrid/sendgrid-ruby/blob/9dd0cf6c9eb7ecc1e4fe2824f9638468ab5fc818/lib/sendgrid/helpers/mail/email.rb

module SendGrid
  class Email

    attr_accessor :email, :name

    def initialize(email: nil, name: nil)

...

并且从文档中:https://github.com/sendgrid/sendgrid-ruby#with-mail-helper-class