为什么在 Gemfile 中包含 gem 可以解决 railtie 问题,即使 gem 已经包含在 Gemfile.lock 中?
Why does including a gem in Gemfile resolve a railtie issue, even though this same gem is already included in Gemfile.lock?
我正在努力思考为什么我一直在努力解决的问题现在神奇地得到了解决。
我正在构建一个使用 Spotify OAuth(通过 rspotify
gem)的 Rails 应用程序并卡住了 on the exact issue described here. After spinning my wheels, I finally came across this comment,建议我明确添加 omniauth
gem 到我的 Gemfile
.
现在,这个 omniauth
gem 已经是 Gemfile.lock
中专门针对 omniauth-oauth2
的依赖项。按照 linked comment 的建议,我将 omniauth
包含在我的 Gemfile 中,现在我的问题似乎已解决,但我真的不知道为什么。
- 为什么在
Gemfile
中包含 gem 可以解决这种情况下的 railtie 问题?
- 如果 gem 已经作为依赖项安装(根据
Gemfile.lock
),这不是给定 gem 已安装的证据吗?例如,如果 gem_foo
在 Gemfile.lock
中被列为依赖项,我在 Gemfile
中添加 gem_foo
,然后在 运行 Bundler 中添加 Rails解释这一变化?
这与 gems
如何被打包器加载有关。 Bundler.require
需要 Gemfile
中列出的 gem,但不需要它的依赖性。它取决于图书馆 require/load 它的依赖性。
当 omniauth
未明确添加到 Gemfile 时会出现上述问题,因此捆绑程序不需要它。
但是由于 omniauth-rails_csrf_protection
假设 ominauth
已经是必需的,当用户只添加 omniauth-rails_csrf_protection
而没有添加 omniauth
到 Gemfile 时会出错。
我已经为这个问题创建了一个可能的修复程序 https://github.com/cookpad/omniauth-rails_csrf_protection/pull/13
更新:此修复已合并到 gem 存储库中。
我正在努力思考为什么我一直在努力解决的问题现在神奇地得到了解决。
我正在构建一个使用 Spotify OAuth(通过 rspotify
gem)的 Rails 应用程序并卡住了 on the exact issue described here. After spinning my wheels, I finally came across this comment,建议我明确添加 omniauth
gem 到我的 Gemfile
.
现在,这个 omniauth
gem 已经是 Gemfile.lock
中专门针对 omniauth-oauth2
的依赖项。按照 linked comment 的建议,我将 omniauth
包含在我的 Gemfile 中,现在我的问题似乎已解决,但我真的不知道为什么。
- 为什么在
Gemfile
中包含 gem 可以解决这种情况下的 railtie 问题? - 如果 gem 已经作为依赖项安装(根据
Gemfile.lock
),这不是给定 gem 已安装的证据吗?例如,如果gem_foo
在Gemfile.lock
中被列为依赖项,我在Gemfile
中添加gem_foo
,然后在 运行 Bundler 中添加 Rails解释这一变化?
这与 gems
如何被打包器加载有关。 Bundler.require
需要 Gemfile
中列出的 gem,但不需要它的依赖性。它取决于图书馆 require/load 它的依赖性。
当 omniauth
未明确添加到 Gemfile 时会出现上述问题,因此捆绑程序不需要它。
但是由于 omniauth-rails_csrf_protection
假设 ominauth
已经是必需的,当用户只添加 omniauth-rails_csrf_protection
而没有添加 omniauth
到 Gemfile 时会出错。
我已经为这个问题创建了一个可能的修复程序 https://github.com/cookpad/omniauth-rails_csrf_protection/pull/13
更新:此修复已合并到 gem 存储库中。