gpt4 book ai didi

ruby-on-rails - `const_get' : uninitialized constant [class] (NameError)` after file save in Docker with Spring

转载 作者:行者123 更新时间:2023-12-04 03:39:37 31 4
gpt4 key购买 nike

我在带有 Spring 和 Guard 的 Docker 中使用 Rails。请参阅保护文件:

guard 'rspec', cmd: "#{env_vars} spring rspec -color -f doc", :all_on_start => false, :all_after_pass => false do watch(%r{^spec/.+_spec\.rb$})

奇怪的问题:当 spring 标记在上面的命令中就位时,我在运行规范时遇到错误,但只有在我以某种方式将文件保存在容器中之后才会出现错误。这是错误:

/usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/inflector/methods.rb:268:in `const_get': uninitialized constant User (NameError)
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/inflector/methods.rb:268:in `block in constantize'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/inflector/methods.rb:266:in `each'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/inflector/methods.rb:266:in `inject'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/inflector/methods.rb:266:in `constantize'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:583:in `get'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:614:in `constantize'
from /usr/local/bundle/gems/devise-4.2.0/lib/devise.rb:301:in `get'
from /usr/local/bundle/gems/devise-4.2.0/lib/devise/mapping.rb:81:in `to'
from /usr/local/bundle/gems/devise-4.2.0/lib/devise/mapping.rb:76:in `modules'
from /usr/local/bundle/gems/devise-4.2.0/lib/devise/mapping.rb:93:in `routes'
from /usr/local/bundle/gems/devise-4.2.0/lib/devise/mapping.rb:160:in `default_used_route'
from /usr/local/bundle/gems/devise-4.2.0/lib/devise/mapping.rb:70:in `initialize'
from /usr/local/bundle/gems/devise-4.2.0/lib/devise.rb:331:in `new'
from /usr/local/bundle/gems/devise-4.2.0/lib/devise.rb:331:in `add_mapping'
from /usr/local/bundle/gems/devise-4.2.0/lib/devise/rails/routes.rb:241:in `block in devise_for'
from /usr/local/bundle/gems/devise-4.2.0/lib/devise/rails/routes.rb:240:in `each'
from /usr/local/bundle/gems/devise-4.2.0/lib/devise/rails/routes.rb:240:in `devise_for'
from /usr/src/app/config/routes.rb:34:in `block in <top (required)>'
from /usr/local/bundle/gems/actionpack-5.0.1/lib/action_dispatch/routing/route_set.rb:389:in `instance_exec'
from /usr/local/bundle/gems/actionpack-5.0.1/lib/action_dispatch/routing/route_set.rb:389:in `eval_block'
from /usr/local/bundle/gems/actionpack-5.0.1/lib/action_dispatch/routing/route_set.rb:371:in `draw'
from /usr/src/app/config/routes.rb:1:in `<top (required)>'
from /usr/local/bundle/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb:40:in `load'
from /usr/local/bundle/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /usr/local/bundle/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb:40:in `each'
from /usr/local/bundle/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /usr/local/bundle/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /usr/local/bundle/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/file_update_checker.rb:77:in `call'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/file_update_checker.rb:77:in `execute'
from /usr/local/bundle/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb:7:in `execute'
from /usr/local/bundle/gems/railties-5.0.1/lib/rails/application/finisher.rb:132:in `block (2 levels) in <module:Finisher>'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:396:in `instance_exec'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:396:in `block in make_lambda'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:169:in `call'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:169:in `block (2 levels) in halting'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:547:in `call'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:547:in `block (2 levels) in default_terminator'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:546:in `catch'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:546:in `block in default_terminator'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:170:in `call'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:170:in `block in halting'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:454:in `call'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:454:in `block in call'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:454:in `each'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:454:in `call'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:750:in `_run_run_callbacks'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:90:in `run_callbacks'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/execution_wrapper.rb:108:in `run!'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/reloader.rb:113:in `run!'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/reloader.rb:48:in `block (2 levels) in reload!'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/reloader.rb:46:in `tap'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/reloader.rb:46:in `block in reload!'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/execution_wrapper.rb:85:in `wrap'
from /usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/reloader.rb:45:in `reload!'
from /usr/local/bundle/gems/spring-1.7.2/lib/spring/application.rb:154:in `serve'
from /usr/local/bundle/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run'
from /usr/local/bundle/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop'
from /usr/local/bundle/gems/spring-1.7.2/lib/spring/application.rb:125:in `run'
from /usr/local/bundle/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
19:33:45 - ERROR - Failed: "BYEBUG=true spring rspec -color -f doc -r /usr/local/bundle/gems/guard-rspec-4.7.3/lib/guard/rspec_formatter.rb -f Guard::RSpecFormatter --failure-exit-code 2 spec/controllers/api/buyside/ideas_controller_spec.rb" (exit code: 1)

如果我在一个新的容器中运行规范,这个错误不会发生,直到我在我COPY 的代码中保存了一个文件。保存任何文件后,我在尝试运行规范时遇到错误。

如果我在没有 spring 标签的情况下运行 guard 命令,我也不会收到错误,但当然我不再享受 spring 预加载的好处,所以性能非常慢。

知道发生了什么事吗?在最近升级到 Rails 5 之前没有这个问题。很高兴发布其他相关信息。

提前致谢。

最佳答案

此问题在此处讨论:rails/spring#519

如该问题中所暗示的那样,解决方法是禁用预先加载。

config/environments/test.rb 中你改变;

config.eager_load = true

config.eager_load = false

关于ruby-on-rails - `const_get' : uninitialized constant [class] (NameError)` after file save in Docker with Spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42376690/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com