Как использовать bundler (0.9.1.pre1) с Rails и CouchRest - PullRequest
2 голосов
/ 09 февраля 2010

Я хочу использовать текущую версию bundler (было несколько изменений с 0,8 до 0,9) для управления драгоценными камнями моего приложения Rails. Сначала я создал Gemfile в корне папки приложения и добавил в него все необходимые драгоценные камни. Затем я поместил (как рекомендовано в руководстве) следующий код в мой 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, кажется, работает нормально, так как закончил с Your bundle is complete!. Но при запуске моего приложения я получаю следующую ошибку:

$ 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

Что здесь не так?

1 Ответ

1 голос
/ 09 февраля 2010

Arrrg, просто нажал кнопку отправки и пришло в голову решение, которое решило проблему. В руководстве по сборщику сказано: «[...] включите следующее в начало вашего кода». Для приложения Rails вы должны поместить упомянутую часть внизу config/environment.rb, чтобы все правильно настроить перед:

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
...