views:

806

answers:

1

I want to use the current version of bundler (there have been quite some changes from 0.8 to 0.9) to mange the gems of my Rails app. First I created a Gemfile in the root of the app folder and added all the needed gems to it. Then I placed (as recommended in the manual) the following code to my config/environment.rb:

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

bundle install seems to work fine as it finished with Your bundle is complete!. But when starting my app I get the following error:

$ ruby script/server  
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant CouchRest (NameError)
        from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
        from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
        from /home/kuf/data/Arbeit/Decodon/2009-05-08-Project_Orange/orangemix/fuse/config/initializers/couchdb.rb:35
        from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in `load_without_new_constant_marking'
        from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in `load'
        from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in'
        from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in `load'
        from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:622:in `load_application_initializers'
         ... 11 levels...
        from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:84
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from script/server:3

What is wrong here?

+1  A: 

Arrrg, just pushed the send button and had an idea that solved the problem. The bundler manual says: "[...] include the following at the beginning of your code." For a Rails app you have to put the mentioned part at the bottom of config/environment.rb to get everything setup correctly before:

RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION

require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|
...
end

# Put the bundler related stuff here!
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
konrad
Thanks for posting this. I was trying to get this working last week with complete failure. I was putting the bundler initialization code BEFORE the Rails initializer though. I ended up switching back to bundler 0.8.1, which is better documented (right now) with Rails 2.3.5.
Luke Francl
Glad this helped you, too. Currently most of the documentation around is for pre 0.9 and much has changed. Hope this will change soon.
konrad
You should accept your answer now, so this stops showing up in the list of unanswered.. :)
Trevoke
Thanks for the hint but stackoverflow prevents the acceptance of an own answers for 2 days. Now it's possible.
konrad