【问题标题】:ROR: What is causing uninitialized constantROR:是什么导致未初始化的常量
【发布时间】:2023-04-11 01:38:01
【问题描述】:

我必须从 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)):

这是导致问题的行(下面的第 2 行)。

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

【问题讨论】:

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


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      • 2015-12-27
      相关资源
      最近更新 更多