Rails - Puma 在尝试启动服务器时出现未初始化常量错误 (WIndows 11)

Rails - uninitialized constant error by Puma when trying to start the server (WIndows 11)

我正在按照本指南创建一个简单的博客应用程序来学习 Rails 的基础知识 - https://guides.rubyonrails.org/v6.1/getting_started.html

当我尝试使用 ruby bin\rails server 运行 服务器时,服务器在 localhost:3000 上成功启动,但是当我在浏览器中打开它时出现以下错误:-

Puma caught this error: uninitialized constant Pers

            constant.const_get(name)
                    ^^^^^^^^^^ (NameError)
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/inflector/methods.rb:286:in `const_get'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/inflector/methods.rb:286:in `block in constantize'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/inflector/methods.rb:284:in `each'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/inflector/methods.rb:284:in `inject'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/inflector/methods.rb:284:in `constantize'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/core_ext/string/inflections.rb:74:in `constantize'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actionpack-6.1.4.6/lib/abstract_controller/helpers.rb:176:in `block in modules_for_helpers'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actionpack-6.1.4.6/lib/abstract_controller/helpers.rb:169:in `map!'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actionpack-6.1.4.6/lib/abstract_controller/helpers.rb:169:in `modules_for_helpers'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actionpack-6.1.4.6/lib/action_controller/metal/helpers.rb:104:in `modules_for_helpers'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-6.1.4.6/lib/rails/engine.rb:507:in `helpers'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-6.1.4.6/lib/rails/railtie.rb:207:in `public_send'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-6.1.4.6/lib/rails/railtie.rb:207:in `method_missing'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actiontext-6.1.4.6/lib/action_text/engine.rb:46:in `block (3 levels) in <class:Engine>'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/lazy_load_hooks.rb:51:in `each'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-6.1.4.6/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actionpack-6.1.4.6/lib/action_controller/base.rb:270:in `<class:Base>'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actionpack-6.1.4.6/lib/action_controller/base.rb:166:in `<module:ActionController>'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actionpack-6.1.4.6/lib/action_controller/base.rb:7:in `<main>'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actionpack-6.1.4.6/lib/action_dispatch/middleware/static.rb:171:in `each_candidate_filepath'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actionpack-6.1.4.6/lib/action_dispatch/middleware/static.rb:100:in `find_file'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actionpack-6.1.4.6/lib/action_dispatch/middleware/static.rb:68:in `attempt'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actionpack-6.1.4.6/lib/action_dispatch/middleware/static.rb:24:in `call'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/actionpack-6.1.4.6/lib/action_dispatch/middleware/host_authorization.rb:119:in `call'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-mini-profiler-2.3.4/lib/mini_profiler/profiler.rb:393:in `call'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/webpacker-5.4.3/lib/webpacker/dev_server_proxy.rb:25:in `perform_request'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-proxy-0.7.2/lib/rack/proxy.rb:67:in `call'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-6.1.4.6/lib/rails/engine.rb:539:in `call'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/puma-5.6.2/lib/puma/configuration.rb:252:in `call'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/puma-5.6.2/lib/puma/request.rb:77:in `block in handle_request'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/puma-5.6.2/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/puma-5.6.2/lib/puma/request.rb:76:in `handle_request'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/puma-5.6.2/lib/puma/server.rb:441:in `process_client'
C:/PROGRA~1/Ruby31-x64/lib/ruby/gems/3.1.0/gems/puma-5.6.2/lib/puma/thread_pool.rb:147:in `block in spawn_thread'

几天前,我遇到了完全相同的错误 - uninitialized constant Pers,但我遵循了不同的指南并创建了不同的应用程序。

请注意,当我尝试生成应用程序时,我遇到了 tzinfo-data 问题,我必须使用此解决方案手动解决 -

版本:-

Rails - 6.1.4.6

Ruby - 3.1.1p18 (2022-02-18 revision 53f5fc4236)

Yarn - 1.22.17

Node - v16.14.0

解决方法:-

很明显,版本有冲突。正如 Abhinay 在评论中提到的,我切换到 Ruby 2.7.5,应用程序开始运行。