Rails 7启动Zeitwerk相关报错:从6.1升级至7.0的问题
Rails 6.1 升级到7.0 遇到的运行时问题及后续Zeitwerk错误
问题1:Authlogic 相关未初始化常量错误
升级后出现运行时错误,项目使用了Authlogic gem,但没有对应的config/initializers配置文件,也找不到报错中提及的常量。
报错信息:
uninitialized constant Patches::AuthlogicPasswordPatch (NameError) /myapproot/shared/bundle/ruby/3.3.0/gems/zeitwerk-2.6.16/lib/zeitwerk/cref.rb:91:in `const_get' /myapproot/shared/bundle/ruby/3.3.0/gems/zeitwerk-2.6.16/lib/zeitwerk/cref.rb:91:in get
问题2:Zeitwerk 同名类识别错误
解决上述问题后(参考@alex的评论方案),又碰到Zeitwerk相关问题:即便类处于不同命名空间,Zeitwerk仍无法正确识别同名类,报错如下:
Exception Zeitwerk::NameError in Rack application object (expected file app/services/data_tables/base.rb to define constant Base, but didn't)
启用Zeitwerk日志后,启动应用看到以下提示:
Zeitwerk@rails.main: file app/services/deployment/models/base.rb is ignored because app/services/data_tables/base.rb has precedence
相关文件定义
app/services/deployment/models/base.rb:
module Deployment module Models class Base < ActiveResource::Base ...
app/services/data_tables/base.rb:
module DataTables class Base ...
当前config/application.rb配置
config.autoload_paths += Dir["#{config.root}/app/services/**/"] config.eager_load_paths << "#{Rails.root}/lib" config.eager_load_paths << "#{Rails.root}/app/services"
内容的提问来源于stack exchange,提问作者weetch
相关产品推荐
相关产品推荐

