我正在通过创建一个简单的博客应用程序来学习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问题,我必须使用这个解决方案- 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发布于 2022-02-28 05:40:54
解决方案:-
很明显,和版本有冲突。正如Abhinay在评论中提到的,我切换到Ruby2.7.5,这个应用程序开始工作。
https://stackoverflow.com/questions/71290710
复制相似问题