views:

1015

answers:

4

I recently installed the Bundle gem (stable 2.3.x) with a integrated 3.0 release. The documentation for installing 2.3.x is weak, so I'm looking for help here.

I've done everything from this article on installing and configuring gem bundler (Installing gem bundler, defining Gemfile, adding preinitializer.rb, requiring bundler_gems/environment.rb):

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

I can run script/server successfully, but when I try to access any page via my browser, I get a 500 Internal Server Error claiming many ActionView methods are undefined:

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

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

There has to be some gem dependency failing somewhere or something? Here's my 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"

Any pointers?

+1  A: 

So for configuring gem bundler on Rails 2.3.5:

I changed my preinitializer.rb script to this:

# 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

And removed any Bundler.require_env definitions from config/environment.rb, and all was good.

http://gist.github.com/286099

ajhit406
This looks like it might work, but it's complicated. Calling `Bundler.require_env` in a later phase would also work, no need in plugging in exactly at `load_gems` step.
mislav
That worked for me (not sure why, but not complaining). I also started to get `config.gem: Unpacked gem environment.rb in vendor/gems has no specification file. Run 'rake gems:refresh_specs' to fix this.` errors -- is it save to ignore those?
Jonathan
Hmm this happened to me as well. You could try to just run the task, if that doesn't work, someone else posted a hack: http://stackoverflow.com/questions/2144659/how-to-silence-gem-errors-after-switching-to-bundlerBut I think there's a smarter way to fix it. Maybe just try deleting your Gemfile, then recreating it and running "Gem Bundle" again. Eh...
ajhit406
A: 

Most (or all) of these gems are Rails plugins. You should require them during Rails initialization phase. Stick this in your after_initialize:

config.after_initialize do
  Bundler.require_env
end
mislav
What is the best file to put that snipit in? Thanks!
Jonathan
+1  A: 

For reference, bundle is now on 0.9.5. Here is the newest rails 2.3.5 config (you can basically ignore everything else here):

http://gist.github.com/302406

ajhit406
A: 

Updated as Gem Bundler Documentation improves:

http://gembundler.com/rails23.html

ajhit406