我正在努力弄清楚为什么我一直困扰的问题现在神奇地得到了解决。
我正在构建一个使用 Spotify OAuth(通过 rspotify
gem)的 Rails 应用程序并陷入困境 on the exact issue described here 。转了转,终于来了across this comment ,建议我将 omniauth
gem 显式添加到我的 Gemfile
中。
现在,这个 omniauth
gem 已经成为 Gemfile.lock
中针对 omniauth-oauth2
的依赖项。作为linked comment建议,我在 Gemfile 中包含了 omniauth
,现在我的问题似乎已经解决,但我真的不知道为什么。
- 为什么在您的
Gemfile
中包含 gem 可以解决这种情况下的 Railtie 问题? - 如果 gem 已作为依赖项安装(根据
Gemfile.lock
),这不是安装了给定 gem 的证据吗?比如说,如果gem_foo
被列为Gemfile.lock
中的依赖项,并且我在Gemfile
中添加gem_foo
,然后运行 Bundler,Rails 如何解释此更改?
最佳答案
这与 bundler 如何加载gems
有关。 Bundler.require
需要 Gemfile
中列出的 gem,但不需要其依赖项。由库来要求/加载其依赖项。
当 omniauth
未显式添加到 Gemfile 时,会发生上述问题,因此 bundler 不需要它。
但是由于 omniauth-rails_csrf_protection
假定已经需要 ominauth
,因此当用户仅添加 omniauth-rails_csrf_protection
但不添加时会出错omniauth
到 Gemfile。
我已经为该问题创建了一个可能的修复方案 https://github.com/cookpad/omniauth-rails_csrf_protection/pull/13
更新:该修复已合并到 gem 存储库中。
关于ruby-on-rails - 为什么在 Gemfile 中包含一个 gem 可以解决 Railtie 问题,即使这个 gem 已经包含在 Gemfile.lock 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69650988/