kon*_*yak 4 ruby-on-rails gemfile spring-gem
为什么我的 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
Run Code Online (Sandbox Code Playgroud)
当我运行bundle exec rails console test(对于test环境)时,spring 进程启动并且Listen模块被加载到 Rails 控制台中。我确保事先停止所有弹簧进程。
为了进行健全性检查,我删除了上面的整个开发组并进行了捆绑。正如我所料,Spring 和 Listen gem 不再加载。
我在生产中遇到了这个误解。
我是这样解决的:
您还可以通过升级(从中删除 spring gem)可执行文件来永久bin/解决此问题:
bin/spring binstub --remove --all
Run Code Online (Sandbox Code Playgroud)
或者
spring binstub --remove --all
Run Code Online (Sandbox Code Playgroud)
您现在可以运行以下命令进入生产环境中的 Rails 控制台
rails c --environment=production
Run Code Online (Sandbox Code Playgroud)
另外,为了避免在以后的情况下发生这种情况,请尽力确保spring gem 仅出现在Gemfile 中的development和组中。test
此外,当您在生产中时,请确保始终--without development test向bundle install命令提供参数
bundle install --without development test
Run Code Online (Sandbox Code Playgroud)
而不是通常或常见的
bundle install
Run Code Online (Sandbox Code Playgroud)
请注意:作为指示,每当您运行命令rails c或时rails console,您都会看到以下输出:
在进程 26651 中通过 Spring 预加载器运行 警告:Spring 正在生产中运行。要解决此问题,请确保 spring gem 仅存在于Gemfile 中的组
development中test,并确保始终bundle install --without development test在生产中使用
这表明spring gem 正在您的生产环境中运行,应该将其停止或从 bin 可执行文件中完全删除。
就这样。
我希望这有帮助
| 归档时间: |
|
| 查看次数: |
4435 次 |
| 最近记录: |