Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 设计未初始化的Mailer常量_Ruby On Rails_Devise - Fatal编程技术网

Ruby on rails 设计未初始化的Mailer常量

Ruby on rails 设计未初始化的Mailer常量,ruby-on-rails,devise,Ruby On Rails,Devise,我在本教程中非常喜欢: 在生产方面,一切正常,但在开发环境方面 NameError(未初始化的常量MyMailer): 在设计初始值设定项中,我有 config.mailer=“MyMailer” 看起来它只是为了生产而换的 更新 这就是问题所在 config.eager\u load=false在开发环境中 当设置为true时,一切正常,就像在生产中一样 那么,什么是变通办法?我不确定我是否应该这样设置 mailers/mymailer.rb class MyMailer

我在本教程中非常喜欢: 在生产方面,一切正常,但在开发环境方面

NameError(未初始化的常量MyMailer):

在设计初始值设定项中,我有
config.mailer=“MyMailer”

看起来它只是为了生产而换的

更新 这就是问题所在

config.eager\u load=false
在开发环境中

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

那么,什么是变通办法?我不确定我是否应该这样设置

mailers/mymailer.rb

class MyMailer
在开发模式下,Rails试图通过名称查找(自动加载)类定义。确保
MyMailer
类在名为
my_mailer.rb
的文件中定义,并放置在类自动加载时Rails搜索的目录之一,例如
mailers
模型
服务
,是否重新启动服务器?是,我找到了解决方案,我将在Sec中发布更新。您将
my_mailer.rb
文件放在哪里了?放在mailers/mymailer.rb中,所以它应该是my_mailer.rb,不mymailer\u mailer.rb?它必须是mailers/my\u mailer.rb,但为什么它在生产中起作用?eager\u加载找到的任何内容?是的,从
Rails.application.config.eager\u加载路径加载所有内容
ok,因此它在开始时加载生产中的所有内容,而在dev中,它每次只需重新加载所需的文件,然后只需“my\u mailer”
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'
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