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

Time:03-03

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

CodePudding user response:

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.

  • Related