ruby-on-rails Rails 5.2,不稳定的“无法自动加载常量”:有时有效,有时无效

2skhul33  于 7个月前  发布在  Ruby
关注(0)|答案(1)|浏览(85)

我有一个观点,ajax加载相同的partial多次。每一次都包含一个相当广泛的计算结果,需要数秒。在我的机器上,大约20次中有3次,而不是partial,我得到错误消息“Unable to autoload constant Answers::Node::Questions::KurzSinglePunch.预期./app/models/answers/node/questions/kurz_single_punch.rb来定义它”(我缩短了文本和路径的易读性)。文件显然是存在的,因为在20个案例中有17个案例找到了它,并且在这些案例中部分正确显示。
如果这是相关的,我在一台运行OS 11.6的六岁Mac上使用Puma的单一模式。
这是错误消息的最高部分:

LoadError in KurzReportsController#company Unable to autoload constant Answers::Node::Questions::KurzSinglePunch, 
expected /Users/marion/Documents/Projekte/myproject/app/models/answers/node/questions/kurz_single_punch.rb to define it 
Extracted source (around line #511): 
#509 else 
#510 require_or_load(expanded, qualified_name) 
*511 raise LoadError, 
"Unable to autoload constant #{qualified_name}, expected #{file_path} to define it" unless from_mod.const_defined?(const_name, false) 
#512 return from_mod.const_get(const_name) 
#513 end 
#514 elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix) 
Extracted source (around line #195): 
#193 def const_missing(const_name) 
#194 from_mod = anonymous? ? guess_for_anonymous(const_name) : self 
*195 Dependencies.load_missing_constant(from_mod, const_name) 
#196 end 
#197 
#198 # 
We assume that the name of the module reflects the nesting 
Extracted source (around line #285): 
#283 constant.const_get(name) 
#284 else 
*285 candidate = constant.const_get(name) 
#286 next candidate if constant.const_defined?(name, false) 
#287 next candidate unless Object.const_defined?(name) 
#288 Rails.root: /Users/marion/Documents/Projekte/myproject 
Application Trace app/exporters/kurz_report_extractor.rb:63:
in `infos_for_question_id' app/exporters/kurz_report_extractor.rb:59:
in `block in build_survey_hash' app/exporters/kurz_report_extractor.rb:59:
in `map' app/exporters/kurz_report_extractor.rb:59:
in `build_survey_hash' app/exporters/kurz_report_extractor.rb:15:
in `initialize' app/controllers/kurz_reports_controller.rb:27:
in `new' app/controllers/kurz_reports_controller.rb:27:
in `block in company' app/controllers/kurz_reports_controller.rb:25:
in `each' app/controllers/kurz_reports_controller.rb:25:in `company'

字符串
在那之后有一个很长的一段框架跟踪。
为什么Rails * 有时 * 找不到这个文件?我该如何解决这个问题?

jk9hmnmh

jk9hmnmh1#

这只是一个初步的答案。我认为,(这是非常先进的)发送AJAX的速度如此之快,以至于运行在旧Mac上的Rails,在开发模式下,不能正确地服务传入的请求,实际上开始绊倒自己的脚。我这样认为的原因是,在AJAX调用之间引入一毫秒的等待时间可以解决这个问题。生产服务器问题不会发生,因为它是一台更新得多、功能更强大的机器,运行在生产模式下,也适合。
(实际上我倾向于将其归类为puma中的一个bug,但由于我在任何地方都找不到它(所以它不是一个常见的问题),并且由于我使用的版本相当旧,我不会做任何事情。

相关问题