gpt4 book ai didi

ruby-on-rails - Spring gem 在错误的环境中加载

转载 作者:行者123 更新时间:2023-12-05 02:16:53 25 4
gpt4 key购买 nike

为什么我的 spring gem 在错误的(或所有)环境中加载?

我的 Gemfile 中有这个,而 spring gem 没有在文件的其他任何地方列出:

group :development do
gem 'listen', '~> 3.1.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end

当我运行 bundle exec rails console test(针对 test 环境)时,spring 进程启动并且 Listen 模块被加载到 rails 控制台。我确保事先停止了所有 spring 进程。

为了进行健全性检查,我删除了上面的整个开发组并进行了捆绑。如我所料,不再加载 Spring 和 listen gem。

最佳答案

我在生产中遇到过这种误解。

我是这样解决的:

您还可以永久解决此问题,方法是启动(从中删除 spring gem)您的 bin/ 可执行文件:

bin/spring binstub --remove --all

或者

spring binstub --remove --all

您现在可以运行以下命令进入生产环境中的 Rails 控制台

rails c --environment=production

此外,为避免在后续场合发生这种情况,请努力确保 spring gem 仅存在于 Gemfile 中的 developmenttest 组中。

此外,当您在生产环境中时,请确保始终向 bundle install 命令提供 --without development test 参数

bundle install --without development test

而不是通常的或常见的

bundle install

请注意:作为指示,每当您运行命令 rails crails console 时,您都会看到以下输出:

Running via Spring preloader in process 26651 WARNING: Spring is running in production. To fix this make sure the spring gem is only present in development and test groups in your Gemfile and make sure you always use bundle install --without development test in production

这表明 spring gem 正在您的生产环境中运行,应将其停止或从您的 bin 可执行文件中完全删除。

就这些。

希望对您有所帮助

关于ruby-on-rails - Spring gem 在错误的环境中加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48916326/

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