ruby – NoMethodError:未定义的方法ascii_only? – 邮件2.5.4和rails 4.0出错

当我尝试使用邮件2.5.4 / rails 4.0.0 / ruby​​ 1.9.3-p125配置发送邮件时,请查找以下错误消息.

SubscriptionMailer.send_email(Subscription.last).deliver
  Subscription Load (0.6ms)  SELECT `subscriptions`.* FROM `subscriptions` ORDER BY `subscriptions`.`id` DESC LIMIT 1
  User Load (0.3ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
  Rendered subscription_mailer/send_email.text.erb (0.6ms)
  Rendered subscription_mailer/send_email.html.haml (5.7ms)
NoMethodError: undefined method `ascii_only?' for nil:NilClass
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/encodings.rb:68:in `param_encode'
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/fields/content_type_field.rb:95:in `block in stringify'
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/fields/content_type_field.rb:95:in `each'
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/fields/content_type_field.rb:95:in `map'
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/fields/content_type_field.rb:95:in `stringify'
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/fields/content_type_field.rb:88:in `value'
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/fields/content_type_field.rb:28:in `parse'
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/fields/content_type_field.rb:24:in `initialize'
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/field.rb:203:in `new'
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/field.rb:203:in `new_field'
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/field.rb:192:in `create_field'
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/field.rb:149:in `update'
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/header.rb:170:in `[]='
  from /opt/blog/vendor/ruby/1.9.1/gems/mail-2.5.4/lib/mail/message.rb:588:in `content_type='
  from /opt/blog/vendor/ruby/1.9.1/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:695:in `mail'
  from /opt/blog/app/mailers/subscription_mailer.rb:19:in `send_email'
... 8 levels...
  from /opt/blog/vendor/ruby/1.9.1/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:497:in `initialize'
  from /opt/blog/vendor/ruby/1.9.1/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:480:in `new'
  from /opt/blog/vendor/ruby/1.9.1/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:480:in `method_missing'
  from (irb):4
  from /opt/blog/vendor/ruby/1.9.1/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
  from /opt/blog/vendor/ruby/1.9.1/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
  from /opt/blog/vendor/ruby/1.9.1/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
  from /opt/blog/vendor/ruby/1.9.1/gems/railties-4.0.0/lib/rails/app_rails_loader.rb:43:in `require'
  from /opt/blog/vendor/ruby/1.9.1/gems/railties-4.0.0/lib/rails/app_rails_loader.rb:43:in `block in exec_app_rails'
  from /opt/blog/vendor/ruby/1.9.1/gems/railties-4.0.0/lib/rails/app_rails_loader.rb:32:in `loop'
  from /opt/blog/vendor/ruby/1.9.1/gems/railties-4.0.0/lib/rails/app_rails_loader.rb:32:in `exec_app_rails'
  from /opt/blog/vendor/ruby/1.9.1/gems/railties-4.0.0/lib/rails/cli.rb:6:in `<top (required)>'
  from /opt/blog/vendor/ruby/1.9.1/gems/railties-4.0.0/bin/rails:9:in `require'
  from /opt/blog/vendor/ruby/1.9.1/gems/railties-4.0.0/bin/rails:9:in `<top (required)>'
  from bin/rails:16:in `load'
  from bin/rails:16:in `<main>'1.9.1 :005 >

解决方法

发送附件时发生了类似的问题.

我需要将附件[:report]更改为附件[‘report’]

旧:

def email_report(电子邮件,报告)
    附件[:report] = File.read(报告)
    mail(to:email,subject:’report’)
结束

新:

def email_report(电子邮件,报告)
    附件[‘report’] = File.read(报告)
    mail(to:email,subject:’report’)
结束

我怀疑发生了类似的事情.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...