代码之家  ›  专栏  ›  技术社区  ›  ajhit406

Rails Gem Bundler中断依赖项

  •  1
  • ajhit406  · 技术社区  · 15 年前

    我最近安装了Bundle gem(stable 2.3.x)和一个集成的3.0版本。安装2.3.x的文档很薄弱,所以我在这里寻求帮助。

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

    我可以成功运行脚本/服务器,但是当我试图通过浏览器访问任何页面时,我会收到一个500内部服务器错误,声称许多ActionView方法未定义:

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

    一定有一些宝石依赖性在某个地方失败了?这是我的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"
    

    有什么线索吗?

    4 回复  |  直到 15 年前
        1
  •  1
  •   ajhit406    15 年前

    因此,要在Rails 2.3.5上配置gem bundler:

    # 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

        2
  •  1
  •   ajhit406    15 年前

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

    http://gist.github.com/302406

        3
  •  0
  •   mislav Telemachus    15 年前

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

    config.after_initialize do
      Bundler.require_env
    end
    
        4
  •  0
  •   ajhit406    14 年前