【问题标题】:Rails Gem Bundler breaking DependenciesRails Gem Bundler 打破依赖关系
【发布时间】:2010-01-25 18:07:01
【问题描述】:

我最近安装了带有集成 3.0 版本的 Bundle gem(稳定的 2.3.x)。安装 2.3.x 的文档很弱,所以我在这里寻求帮助。

我已经完成了本文中关于安装和配置 gem bundler 的所有工作(安装 gem bundler、定义 Gemfile、添加 preinitializer.rb、需要 bundler_gems/environment.rb):

http://litanyagainstfear.com/blog/2009/10/14/gem-bundler-is-the-future/

我可以成功运行脚本/服务器,但是当我尝试通过浏览器访问任何页面时,我收到 500 Internal Server Error 声称许多 ActionView 方法未定义:

ActionView::TemplateError (undefined method `debug' ...

ActionView::TemplateError (undefined method `javascript_tag' ... 

一定有一些gem依赖在某个地方失败了?这是我的 Gemfile (rails 2.3.5):

clear_sources
bundle_path "vendor/bundler_gems"

source "http://gems.github.com"
source "http://gemcutter.org"

gem "rails", "2.3.5"
gem "formtastic"
gem "authlogic"
gem "will_paginate"
gem "cancan"

任何指针?

【问题讨论】:

  • 捆绑器文档很糟糕。

标签: ruby-on-rails bundle gem


【解决方案1】:

所以在 Rails 2.3.5 上配置 gem bundler:

我将我的 preinitializer.rb 脚本更改为:

# Load the environment constructed from the Gemfile
require "#{File.dirname(__FILE__)}/../vendor/bundler_gems/environment"

module Rails
  class Boot
    def run
      load_initializer
      extend_environment
      Rails::Initializer.run(:set_load_path)
    end

    def extend_environment
      Rails::Initializer.class_eval do
        old_load = instance_method(:load_gems)
        define_method(:load_gems) do
          old_load.bind(self).call
          Bundler.require_env RAILS_ENV
        end
      end
    end
  end
end

并从 config/environment.rb 中删除了任何 Bundler.require_env 定义,一切都很好。

http://gist.github.com/286099

【讨论】:

  • 这看起来可能有效,但它很复杂。在稍后的阶段调用Bundler.require_env 也可以,无需在load_gems 步骤准确插入。
  • 这对我有用(不知道为什么,但没有抱怨)。我也开始收到config.gem: Unpacked gem environment.rb in vendor/gems has no specification file. Run 'rake gems:refresh_specs' to fix this. 错误——是否可以忽略这些错误?
  • 嗯这也发生在我身上。您可以尝试只运行该任务,如果这不起作用,其他人发布了一个 hack:stackoverflow.com/questions/2144659/… 但我认为有一个更聪明的方法来解决它。也许只是尝试删除您的 Gemfile,然后重新创建它并再次运行“Gem Bundle”。呃……
【解决方案2】:

作为参考,bundle 现在是 0.9.5。这是最新的 rails 2.3.5 配置(您基本上可以在这里忽略其他所有内容):

http://gist.github.com/302406

【讨论】:

    【解决方案3】:

    这些 gem 中的大部分(或全部)都是 Rails 插件。您应该在 Rails 初始化阶段需要它们。把这个贴在你的after_initialize

    config.after_initialize do
      Bundler.require_env
    end
    

    【讨论】:

    • 什么文件最好放在里面?谢谢!
    【解决方案4】:

    随着 Gem Bundler 文档的改进而更新:

    http://gembundler.com/rails23.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      • 1970-01-01
      • 2012-05-09
      • 2013-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多