`add_template_helper` 方法在 Rails 6.1 中似乎不起作用

Dan*_*iel 21 actionmailer ruby-on-rails-6.1

将我的项目更新到 Rails 6.1 后,我收到此错误:

NoMethodError:
  undefined method `add_template_helper' for ApplicationMailer:Class
Run Code Online (Sandbox Code Playgroud)

在文档中似乎没有被弃用。

Dan*_*iel 53

因此,显然,此方法在此提交中被删除而没有弃用警告:

https://github.com/rails/rails/commit/cb3b37b37975ceb1d38bec9f02305ff5c14ba8e9

因此,解决此问题的方法是替换:

class MyMailer < ApplicationMailer
  add_template_helper MyHelper
Run Code Online (Sandbox Code Playgroud)

和:

class MyMailer < ApplicationMailer
  helper MyHelper
Run Code Online (Sandbox Code Playgroud)

  • 哇,我不敢相信我在同一天遇到了完全相同的问题。这对我有用 - 谢谢! (2认同)