要将 gems 从 git 安装到 gems 文件夹而不是 bundler 文件夹中,可以使用 Bundler 的 :git
参数来指定 gems 的安装路径。以下是一个示例解决方法:
# Gemfile
gem 'example_gem', git: 'https://github.com/example/example_gem.git'
# config/application.rb
Bundler.require(*Rails.groups)
module YourApp
class Application < Rails::Application
# ...
# 将 gems 安装到 gems 文件夹
Bundler.require(*Rails.groups)
Bundler.settings[:path] = 'gems'
# ...
end
end
在 Gemfile 中,使用 git
属性指定要安装的 gem 的 git URL。然后,在 config/application.rb 中,使用 Bundler.settings[:path]
将 gems 安装到指定的文件夹(例如 'gems' 文件夹)中。
这样,当运行 bundle install
时,指定的 gem 将从 git 源安装到指定的文件夹中,而不是默认的 bundler 文件夹中。