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

发布于 2025-01-10 12:33:07 字数 6132 浏览 0 评论 0原文

我正在通过创建一个简单的博客应用程序来学习 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'

几天前,我收到了同样的错误 - 未初始化的常量 Pers,但我遵循不同的指南并创建不同的应用程序。

请注意,当我尝试生成应用程序时,两次都遇到了 tzinfo-data 问题,我必须使用此解决方案手动解决该问题 - https://stackoverflow.com/a/54227934/8936298

版本:-

Rails - 6.1.4.6

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

Yarn - 1.22.17

Node - v16.14.0

I am learning the basics of Rails by creating a simple blog app, as per this guide - https://guides.rubyonrails.org/v6.1/getting_started.html

When I try to run the server using ruby bin\rails server, the server successfully starts on localhost:3000, but I get the following error when I open it in browser:-

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'

Couple of days back, I got the same exact error - uninitialized constant Pers, but I was following a different guide and creating a different app.

Note that both the times when I tried to generate the app, I got tzinfo-data issue which I had to solve manually using this solution - https://stackoverflow.com/a/54227934/8936298

Versions:-

Rails - 6.1.4.6

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

Yarn - 1.22.17

Node - v16.14.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二货你真萌 2025-01-17 12:33:07

解决方案:-

显然,版本存在冲突。正如 Abhinay 在评论中提到的,我切换到 Ruby 2.7.5,应用程序开始工作。

Solution:-

Apparently, there was a conflict with the version. As Abhinay mentioned in the comment, I switched to Ruby 2.7.5, and the app started working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文