ROR actionmailer中nil:NilClass的未定义方法'charset ='

时间:2018-07-12 15:25:36

标签: ruby-on-rails email

我尝试发送基本电子邮件,并且ROR给我发一个错误:

undefined method `charset=' for nil:NilClass

我的课:

class MonitoringAlertMailer < ActionMailer::Base
    default from: "myadmin@myadmin.com"    
   def monitoring_alert
            mail( to: 'myemail@email.com',     body: 'test',   content_type: "text/html",    subject: "test")
    end
end

错误来自:

ruby-2.3.1/gems/actionmailer-5.0.0.1/lib/action_mailer/base.rb:808:in `mail'


 def mail(headers = {}, &block)
      return message if @_mail_was_called && headers.blank? && !block

      # At the beginning, do not consider class default for content_type
      content_type = headers[:content_type]

      headers = apply_defaults(headers)

      # Apply charset at the beginning so all fields are properly quoted
      message.charset = charset = headers[:charset]

其中消息对象为nil 请注意,当我发送带有测试代码的电子邮件时,效果很好

ActionMailer::Base.mail(
  from: "test@example.co", 
  to: "valid.recipient@domain.com", 
  subject: "Test", 
  body: "Test"
).deliver

提前谢谢

1 个答案:

答案 0 :(得分:0)

经过2天的调试。 从rails','〜> 5.0.0'升级到rails rails','〜> 5.0.1'

相关问题