【问题标题】:Why does including a gem in Gemfile resolve a railtie issue, even though this same gem is already included in Gemfile.lock?为什么在 Gemfile 中包含 gem 可以解决 railtie 问题,即使 Gemfile.lock 中已经包含了相同的 gem?
【发布时间】:2021-12-07 13:40:47
【问题描述】:

我正在努力思考为什么我一直在努力解决的问题现在神奇地解决了。

我正在构建一个使用 Spotify OAuth 的 Rails 应用程序(通过 rspotify gem)并卡住了 on the exact issue described here。在旋转我的轮子之后,我终于来到了across this comment,建议我明确地将omniauth gem 添加到我的Gemfile

现在,这个 omniauth gem 已经是 Gemfile.lock 中的一个依赖项,专门用于 omniauth-oauth2。正如linked comment 建议的那样,我将omniauth 包含在我的Gemfile 中,现在我的问题似乎已经解决了,但我真的不知道为什么。

  • 为什么在您的 Gemfile 中包含 gem 可以解决这种情况下的 railtie 问题?
  • 如果一个 gem 已经作为依赖项安装了(根据Gemfile.lock),这不就是安装给定 gem 的证据吗?例如,如果 gem_fooGemfile.lock 中列为依赖项,我在 Gemfile 中添加 gem_foo 然后运行 ​​Bundler,Rails 如何解释此更改?

【问题讨论】:

    标签: ruby-on-rails ruby rubygems bundler


    【解决方案1】:

    这与捆绑程序如何加载gems 有关。 Bundler.require 需要 Gemfile 中列出的 gem,但不需要它的依赖。它由库来要求/加载其依赖项。

    omniauth 未显式添加到 Gemfile 时会发生上述问题,因此捆绑程序不需要它。

    但是由于omniauth-rails_csrf_protection 假定ominauth 已经是必需的,所以当用户只添加omniauth-rails_csrf_protection 而没有将omniauth 添加到Gemfile 时会出错。

    我已经为问题https://github.com/cookpad/omniauth-rails_csrf_protection/pull/13创建了一个可能的修复程序

    更新:该修复已合并到 gem 存储库中。

    【讨论】:

    • 感谢@the_spectator,这回答了我的问题并解决了问题。再次感谢您提供有关实际宝石的修复程序!
    猜你喜欢
    • 2012-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多