gpt4 book ai didi

ruby-on-rails - bundler 错误地尝试在生产中安装 "development"和 "test"组 gems

转载 作者:行者123 更新时间:2023-12-03 10:49:02 25 4
gpt4 key购买 nike

我有一个小型网络应用程序,它使用了一堆 gem 。其中一些仅用于testdevelopment环境。现在,当我尝试使用以下命令在生产服务器上启动 unicorn 时,它失败了。

unicorn_rails -E production -D -c config/unicorn.rb

我在日志文件中看到的错误是:
Refreshing Gem list
Could not find gem 'spork (>= 0.9.0.rc2, runtime)' in any of the gem sources listed in your Gemfile.
Try running `bundle install`.

我在下面粘贴了我的 gemfile:
source 'http://rubygems.org'

gem 'rails', '3.0.1'
gem 'unicorn'
gem 'mongoid', '>= 2.0.0.beta.19'
gem 'devise'
gem 'cancan'
gem 'haml', '>= 3.0.0'
gem 'bson'
gem 'bson_ext'
gem 'formtastic'
gem 'bluecloth'

group :production do
gem 'capistrano'
end

group :development do
gem 'haml-rails'
gem 'hpricot', '0.8.2'
gem 'ruby_parser', '2.0.5'
gem 'less'
gem 'rspec-rails', '>= 2.0.1'
end

group :development,:test do
gem 'spork', '>=0.9.0.rc2'
gem 'mongoid-rspec'
end

group :test do
gem 'factory_girl_rails'
gem 'autotest'
gem 'cucumber-rails'
gem 'cucumber'
gem 'capybara'
gem 'shoulda'
gem 'database_cleaner'
gem 'test_notifier'
gem 'rspec', '2.0.1'
gem 'launchy'
end

Bundler 应该检测正确的环境并忽略其他 gem,对吗?现在,我正在删除所有不在服务器默认组中的行以使其正常工作,但这是一个丑陋的黑客。

最佳答案

经过大量挖掘,我找到了解决此问题的方法。我所要做的就是运行 bundle install --without development test在启动服务器之前。这增加了一个 .bundle/config文件在 rails 根目录中,行 BUNDLE_WITHOUT: test:development .现在只要你运行 bundle install或启动服务器它会忽略这些组。

From the documentation

The Bundler CLI allows you to specify a list of groups whose gems bundle install should not install with the --without option. To specify multiple groups to ignore, specify a list of groups separated by spaces.

bundle install --without test bundle install --without development test After running bundle install --without test, bundler will remember that you excluded the test group in the last installation. The next time you run bundle install, without any --without option, bundler will recall it.

Also, calling Bundler.setup with no parameters, or calling require "bundler/setup" will setup all groups except for the ones you excluded via --without (since they are obviously not available).

关于ruby-on-rails - bundler 错误地尝试在生产中安装 "development"和 "test"组 gems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4438601/

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