设计 Mailer 未初始化常量

Devise Mailer uninitialized constant

我在本教程中所做的一切都是这样的: https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer 在生产环境中一切正常,但在开发环境中我得到

NameError(未初始化常量 MyMailer):

bootsnap (1.3.1) lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in `block in load_missing_constant'
bootsnap (1.3.1) lib/bootsnap/load_path_cache/core_ext/active_support.rb:8:in `without_bootsnap_cache'
bootsnap (1.3.1) lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in `rescue in load_missing_constant'
bootsnap (1.3.1) lib/bootsnap/load_path_cache/core_ext/active_support.rb:42:in `load_missing_constant'

我正在设计初始值设定项 config.mailer = "MyMailer"'

它似乎只对生产进行了更改。

更新 所以关于这个

config.eager_load = false 在开发环境中

当设置为 true 时,一切正常,就像在生产环境中一样。

那么解决方法是什么?我不确定是否应该这样设置。

mailers/mymailer.rb

class MyMailer < Devise::Mailer   
  helper :application # gives access to all helpers defined within `application_helper`.
  include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
  default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views
  include DefaultUrlOptions
end

在开发模式下 Rails 尝试通过名称查找(自动加载)class 定义。确保 MyMailer class 在名为 my_mailer.rb 的文件中定义,并放置在 class 自动加载时 Rails 搜索的目录之一,例如 mailers, models, services.