Bundler 未加载 gem

2024-02-19

我在使用 Bundler 和能够访问我的宝石而不需要在某个地方需要它们时遇到了问题,因为config.gem曾经为我这样做过(据我所知)。在我的 Rails 3 应用程序中,我定义了我的Gemfile像这样:

clear_sources
source "http://gemcutter.org"
source "http://gems.github.com"
bundle_path "vendor/bundler_gems"

## Bundle edge rails:
git "git://github.com/rails/arel.git"
git "git://github.com/rails/rack.git"
gem "rails", :git => "git://github.com/rails/rails.git"

## Bundle
gem "mongo_mapper", :git => "git://github.com/jnunemaker/mongomapper.git"
gem "bluecloth", ">= 2.0.0"

然后我跑gem bundle,它按照预期将所有内容捆绑在一起。在 - 的里面environment.rb包含在其中的文件boot.rb它看起来像这样:

# DO NOT MODIFY THIS FILE
module Bundler
 file = File.expand_path(__FILE__)
 dir = File.dirname(file)

  ENV["PATH"]     = "#{dir}/../../../../bin:#{ENV["PATH"]}"
  ENV["RUBYOPT"]  = "-r#{file} #{ENV["RUBYOPT"]}"

  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/builder-2.1.2/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/builder-2.1.2/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/text-hyphen-1.0.0/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/text-hyphen-1.0.0/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/i18n-0.3.3/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/i18n-0.3.3/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/arel/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/arel/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/activemodel/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/activemodel/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/jnunemaker-validatable-1.8.1/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/jnunemaker-validatable-1.8.1/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/abstract-1.0.0/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/abstract-1.0.0/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/erubis-2.6.5/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/erubis-2.6.5/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/mime-types-1.16/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/mime-types-1.16/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/mail-2.1.2/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/mail-2.1.2/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rake-0.8.7/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rake-0.8.7/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/railties/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/railties/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/memcache-client-1.7.7/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/memcache-client-1.7.7/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rack/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rack/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-test-0.5.3/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-test-0.5.3/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-mount-0.4.5/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-mount-0.4.5/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/actionpack/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/actionpack/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/bluecloth-2.0.7/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/bluecloth-2.0.7/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/bluecloth-2.0.7/ext")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/activerecord/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/activerecord/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/text-format-1.0.0/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/text-format-1.0.0/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/actionmailer/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/actionmailer/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/tzinfo-0.3.16/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/tzinfo-0.3.16/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/activesupport/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/activesupport/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/activeresource/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/activeresource/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/rails/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/mongo-0.18.2/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/mongo-0.18.2/lib")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/mongomapper/bin")
  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/mongomapper/lib")

  @gemfile = "#{dir}/../../../../Gemfile"

  require "rubygems" unless respond_to?(:gem) # 1.9 already has RubyGems loaded

  @bundled_specs = {}
  @bundled_specs["builder"] = eval(File.read("#{dir}/specifications/builder-2.1.2.gemspec"))
  @bundled_specs["builder"].loaded_from = "#{dir}/specifications/builder-2.1.2.gemspec"
  @bundled_specs["text-hyphen"] = eval(File.read("#{dir}/specifications/text-hyphen-1.0.0.gemspec"))
  @bundled_specs["text-hyphen"].loaded_from = "#{dir}/specifications/text-hyphen-1.0.0.gemspec"
  @bundled_specs["i18n"] = eval(File.read("#{dir}/specifications/i18n-0.3.3.gemspec"))
  @bundled_specs["i18n"].loaded_from = "#{dir}/specifications/i18n-0.3.3.gemspec"
  @bundled_specs["arel"] = eval(File.read("#{dir}/specifications/arel-0.2.pre.gemspec"))
  @bundled_specs["arel"].loaded_from = "#{dir}/specifications/arel-0.2.pre.gemspec"
  @bundled_specs["activemodel"] = eval(File.read("#{dir}/specifications/activemodel-3.0.pre.gemspec"))
  @bundled_specs["activemodel"].loaded_from = "#{dir}/specifications/activemodel-3.0.pre.gemspec"
  @bundled_specs["jnunemaker-validatable"] = eval(File.read("#{dir}/specifications/jnunemaker-validatable-1.8.1.gemspec"))
  @bundled_specs["jnunemaker-validatable"].loaded_from = "#{dir}/specifications/jnunemaker-validatable-1.8.1.gemspec"
  @bundled_specs["abstract"] = eval(File.read("#{dir}/specifications/abstract-1.0.0.gemspec"))
  @bundled_specs["abstract"].loaded_from = "#{dir}/specifications/abstract-1.0.0.gemspec"
  @bundled_specs["erubis"] = eval(File.read("#{dir}/specifications/erubis-2.6.5.gemspec"))
  @bundled_specs["erubis"].loaded_from = "#{dir}/specifications/erubis-2.6.5.gemspec"
  @bundled_specs["mime-types"] = eval(File.read("#{dir}/specifications/mime-types-1.16.gemspec"))
  @bundled_specs["mime-types"].loaded_from = "#{dir}/specifications/mime-types-1.16.gemspec"
  @bundled_specs["mail"] = eval(File.read("#{dir}/specifications/mail-2.1.2.gemspec"))
  @bundled_specs["mail"].loaded_from = "#{dir}/specifications/mail-2.1.2.gemspec"
  @bundled_specs["rake"] = eval(File.read("#{dir}/specifications/rake-0.8.7.gemspec"))
  @bundled_specs["rake"].loaded_from = "#{dir}/specifications/rake-0.8.7.gemspec"
  @bundled_specs["railties"] = eval(File.read("#{dir}/specifications/railties-3.0.pre.gemspec"))
  @bundled_specs["railties"].loaded_from = "#{dir}/specifications/railties-3.0.pre.gemspec"
  @bundled_specs["memcache-client"] = eval(File.read("#{dir}/specifications/memcache-client-1.7.7.gemspec"))
  @bundled_specs["memcache-client"].loaded_from = "#{dir}/specifications/memcache-client-1.7.7.gemspec"
  @bundled_specs["rack"] = eval(File.read("#{dir}/specifications/rack-1.1.0.gemspec"))
  @bundled_specs["rack"].loaded_from = "#{dir}/specifications/rack-1.1.0.gemspec"
  @bundled_specs["rack-test"] = eval(File.read("#{dir}/specifications/rack-test-0.5.3.gemspec"))
  @bundled_specs["rack-test"].loaded_from = "#{dir}/specifications/rack-test-0.5.3.gemspec"
  @bundled_specs["rack-mount"] = eval(File.read("#{dir}/specifications/rack-mount-0.4.5.gemspec"))
  @bundled_specs["rack-mount"].loaded_from = "#{dir}/specifications/rack-mount-0.4.5.gemspec"
  @bundled_specs["actionpack"] = eval(File.read("#{dir}/specifications/actionpack-3.0.pre.gemspec"))
  @bundled_specs["actionpack"].loaded_from = "#{dir}/specifications/actionpack-3.0.pre.gemspec"
  @bundled_specs["bluecloth"] = eval(File.read("#{dir}/specifications/bluecloth-2.0.7.gemspec"))
  @bundled_specs["bluecloth"].loaded_from = "#{dir}/specifications/bluecloth-2.0.7.gemspec"
  @bundled_specs["activerecord"] = eval(File.read("#{dir}/specifications/activerecord-3.0.pre.gemspec"))
  @bundled_specs["activerecord"].loaded_from = "#{dir}/specifications/activerecord-3.0.pre.gemspec"
  @bundled_specs["text-format"] = eval(File.read("#{dir}/specifications/text-format-1.0.0.gemspec"))
  @bundled_specs["text-format"].loaded_from = "#{dir}/specifications/text-format-1.0.0.gemspec"
  @bundled_specs["actionmailer"] = eval(File.read("#{dir}/specifications/actionmailer-3.0.pre.gemspec"))
  @bundled_specs["actionmailer"].loaded_from = "#{dir}/specifications/actionmailer-3.0.pre.gemspec"
  @bundled_specs["tzinfo"] = eval(File.read("#{dir}/specifications/tzinfo-0.3.16.gemspec"))
  @bundled_specs["tzinfo"].loaded_from = "#{dir}/specifications/tzinfo-0.3.16.gemspec"
  @bundled_specs["activesupport"] = eval(File.read("#{dir}/specifications/activesupport-3.0.pre.gemspec"))
  @bundled_specs["activesupport"].loaded_from = "#{dir}/specifications/activesupport-3.0.pre.gemspec"
  @bundled_specs["activeresource"] = eval(File.read("#{dir}/specifications/activeresource-3.0.pre.gemspec"))
  @bundled_specs["activeresource"].loaded_from = "#{dir}/specifications/activeresource-3.0.pre.gemspec"
  @bundled_specs["rails"] = eval(File.read("#{dir}/specifications/rails-3.0.pre.gemspec"))
  @bundled_specs["rails"].loaded_from = "#{dir}/specifications/rails-3.0.pre.gemspec"
  @bundled_specs["mongo"] = eval(File.read("#{dir}/specifications/mongo-0.18.2.gemspec"))
  @bundled_specs["mongo"].loaded_from = "#{dir}/specifications/mongo-0.18.2.gemspec"
  @bundled_specs["mongo_mapper"] = eval(File.read("#{dir}/specifications/mongo_mapper-0.6.10.gemspec"))
  @bundled_specs["mongo_mapper"].loaded_from = "#{dir}/specifications/mongo_mapper-0.6.10.gemspec"

  def self.add_specs_to_loaded_specs
    Gem.loaded_specs.merge! @bundled_specs
  end

  def self.add_specs_to_index
    @bundled_specs.each do |name, spec|
      Gem.source_index.add_spec spec
    end
  end

  add_specs_to_loaded_specs
  add_specs_to_index

  def self.require_env(env = nil)
    context = Class.new do
      def initialize(env) @env = env && env.to_s ; end
      def method_missing(*) ; yield if block_given? ; end
      def only(*env)
        old, @only = @only, _combine_only(env.flatten)
        yield
        @only = old
      end
      def except(*env)
        old, @except = @except, _combine_except(env.flatten)
        yield
        @except = old
      end
      def gem(name, *args)
        opt = args.last.is_a?(Hash) ? args.pop : {}
        only = _combine_only(opt[:only] || opt["only"])
        except = _combine_except(opt[:except] || opt["except"])
        files = opt[:require_as] || opt["require_as"] || name
        files = [files] unless files.respond_to?(:each)

        return unless !only || only.any? {|e| e == @env }
        return if except && except.any? {|e| e == @env }

        if files = opt[:require_as] || opt["require_as"]
          files = Array(files)
          files.each { |f| require f }
        else
          begin
            require name
          rescue LoadError
            # Do nothing
          end
        end
        yield if block_given?
        true
      end
      private
      def _combine_only(only)
        return @only unless only
        only = [only].flatten.compact.uniq.map { |o| o.to_s }
        only &= @only if @only
        only
      end
      def _combine_except(except)
        return @except unless except
        except = [except].flatten.compact.uniq.map { |o| o.to_s }
        except |= @except if @except
        except
      end
    end
    context.new(env && env.to_s).instance_eval(File.read(@gemfile), @gemfile, 1)
  end
end

module Gem
  @loaded_stacks = Hash.new { |h,k| h[k] = [] }

  def source_index.refresh!
    super
    Bundler.add_specs_to_index
  end
end

但是当我尝试访问我的任何宝石时,例如MongoMapper, Paperclip, Haml等等。我得到:

NameError: uninitialized constant MongoMapper

对于任何其他宝石也是如此。 Bundler 不包含像旧 Rails 2.0 那样的 gem 吗?或者我的系统出了什么问题?

任何帮助将不胜感激,谢谢!


您需要在 Bundler 上升级到最新版本。完成此操作后,快速删除以前的版本gem cleanup,修复你的 Gemfile,然后执行bundle lock然后将以下代码添加到config/preinitializer.rb file:

begin
  # Require the preresolved locked set of gems.
  require File.expand_path('../.bundle/environment', __FILE__)
rescue LoadError
  # Fallback on doing the resolve at runtime.
  require "rubygems"
  require "bundler"

  Bundler.setup
end

# Auto-require all bundled libraries.
Bundler.require
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Bundler 未加载 gem 的相关文章

随机推荐

  • 为什么 Mac OS X 中的 Mach-O 库需要 install_name_tool 和 otool?

    我正在使用最新版本的 Xcode 4 开发 Cocoa 应用程序 我想将动态库链接到我的项目 dylibs 我在某处读到 在我的项目中添加库是不够的 因为我必须运行install name tool and otool使我的项目使用捆绑在我
  • 从应用程序提示启用 GPS 后如何刷新并获取当前位置?

    我目前正在开发一个 Android 应用程序 如果 GPS 未打开 它会提示用户启用 GPS 并且我已使用警报对话框来实现此目的 在我从设置中启用 GPS 并按后退按钮返回到我的应用程序后 Toast 消息显示 0 00 0 00 尽管如果
  • 在 Android 中使用基于 HTTPS 的 SOAP+XML 请求 Exchange Web Services 2007/2010

    我使用 Microsoft 的以下 C 代码来请求 EWS 2010MSDN链接 http msdn microsoft com en us library cc526065 aspx它起作用了 我需要同样的 Android 解决方案 我尝
  • 如何在asp.net中获取Sigma网格的记录数

    我在用西格玛网格 http www sigmawidgets com products sigma grid2 在一个 ASP NET 项目中 如果数据库返回 null 我想显示没有找到记录 我尝试过一些事情 例如 var grid Sig
  • 为什么我不能分配给 Pandas DataFrame 的一部分?

    我很困惑为什么以下pandas未成功将 A 列的最后两个值分配给 B 列的前两个条目 df pd DataFrame A 1 2 3 4 5 6 7 B 10 20 30 40 50 60 70 df df join pd DataFram
  • 关键事件:ProcessCmdKey

    我试图在一个小测试 Windows 窗体应用程序上获得一些键盘响应 并且我有一个粗略的解决方案 即覆盖 ProcessCmdKey 然而 我遇到了一些问题 并且发现了不一致的地方 不同的事件 有没有办法告诉 在争论中ref Message
  • 具有当前行条件的 Spark 窗口函数

    我正在尝试计算给定的order id过去 365 天内有多少订单已付款 这不是问题 我使用窗函数 https databricks com blog 2015 07 15 introducing window functions in sp
  • JVM 中的最大线程数?

    Java虚拟机最多可以维护多少个线程 我在最初的问题中没有解释这一点 但我正在尝试对 JVM 进行基准测试 并想尝试看看它可以同时维护多少个线程 在循环中创建线程直到引发异常是一种选择 但是 我想知道是否有更好的方法来执行此操作 您的操作系
  • glassfish autodeploy 通过简单的应用程序给出 404

    我安装了普通 glassfish v3 并将我的 war 放入C glassfishv3 glassfish domains domain1 autodeploy我的 Windows PC 的文件夹 战争包含一个用 java JSF ric
  • java.net.SocketException:recvfrom失败:ECONNRESET(连接由对等方重置)

    我在 Android 中有一个 HTTP 服务器 我为每个 HTTP 请求创建一个新线程 如提到的链接中所示 http hc apache org httpcomponents core ga httpcore examples org a
  • 在 vue-formulate 的嵌套组中使用空列表

    我正在使用 vue 和 vue Formulate 并想要构建一个带有嵌套组 https vueformulate com guide inputs types group 例如 我有一个用户 外部组 每个用户可以有一个标签列表 内部组 标
  • 从 kotlin 创建新的节点模块对象

    我正在尝试用 Kotlin 编写一个小型的 node js 应用程序来测试和使用 javascript 互操作 从公开原型 Bar 的外部节点模块 foo 我尝试创建 Bar 的新实例 在Javascript中我会简单地写一些类似的东西 v
  • 在 Angular 中使用源映射生成生产版本 - CLI

    生产构建后如何保留源映射 现在 我的命令如下所示 build prod ng build app release prod cp R lang dist 我尝试将其更改为 ng build app release sourceMap tru
  • 如何获得定义频带内的所有 fft bin 数量?

    我用的是matlab软件 对于我的问题 我有一个音频信号 我正在其上应用 STFT 我取一段 46 ms specifially chosen 我的信号消失了y audio signal 并使用FFT在上面 然后我进入下一段 直到音频信号结
  • 有可用的 FreeRTOS 解释语言库吗?

    我在一家公司工作 该公司使用 FreeRTOS 为多个设备创建固件 最近 我们对新功能的要求已经超出了我们固件工程师的工作能力 但我们现在也无力雇用任何新人 即使进行微小的更改 也需要固件人员在非常低的级别上进行修改 我一直在为 FreeR
  • 如何使用textview.getLayout()?它返回空值

    我正在尝试设置布局textview所以我可以用getEllipsisCount 方法 但下面的代码返回 null 作为布局值 我如何进行布局然后使用getEllipsisCount 0 method public class MainAct
  • Matlab中使用滑块旋转图像

    我在 Matlab 中有一个 GUI 使用 GUIDE 它看起来是这样的 我想使用滑块旋转图像并实时显示变化 我使用轴来显示图像 我怎样才能做到这一点 EDIT 我正在构建 OCR 应用程序 这就是我旋转盘子时的样子 数字完全变形了 tha
  • Mac osx 10.9.2 上的 mysql-python:错误:命令“/usr/bin/clang”失败,退出状态为 1

    我想将我的 django 应用程序从 sqlite 移植到 mysql 但是当我尝试安装 mysql python 时 它给了我这个错误 错误 命令 usr bin clang 失败 退出状态为 1 我四处寻找线索并尝试了这个似乎对大多数人
  • 如何将数据从控制器传递到 ASP.net MVC 中的视图? [复制]

    这个问题在这里已经有答案了 net MVC 我需要做的事情对于我认识的每个人来说都很简单 我需要在控制器之间传递数据以在 ASP net MVC 中查看 我在控制器中编写的代码 public ActionResult Upload View
  • Bundler 未加载 gem

    我在使用 Bundler 和能够访问我的宝石而不需要在某个地方需要它们时遇到了问题 因为config gem曾经为我这样做过 据我所知 在我的 Rails 3 应用程序中 我定义了我的Gemfile像这样 clear sources sou