Edited at

rails 2 系を bundler で動かしてみる

More than 1 year has passed since last update.

古いプロジェクトのデバッグで、rails2 系 を修正しないと行けなくなり、

プロジェクト毎に入れたくて(システムグローバルの gem にも、rbenv の gem にも入れたくない)

bundler で悪戦苦闘した時の備忘録です。


rack のバージョンが合致しない

rails2.3.8 は rack 1.1.6 を要求するのに、

ruby script/console すると actionpack/lib/action_controller.rb が rack <~1.0.1 を要求してくる。

通常の gem なら複数バージョンインストールすれば解決するのですが、bundler 経由のため複数バージョンいれられません。

そこで action_controller.rb の 36行目に ~> 1.0.1 と書かれるているので、下記の様に書き換える。


vendor/rails/actionpack/lib/action_controller.rb

gem 'rack', '~> 1.1.0'



その時のエラーログ

[root $] bundler exec ruby script/console development

Loading development environment (Rails 2.3.5)
/var/www/rails_project/config/../vendor/rails/railties/lib/initializer.rb:271:in `require_frameworks':RuntimeError: can't activate rack (~> 1.0.1, runtime), already activated rack-1.1.6. Make sure all dependencies are added to Gemfile.
/usr/local/rbenv/versions/1.8.7-p371/lib/ruby/gems/1.8/gems/bundler-1.6.2/lib/bundler/rubygems_integration.rb:262:in `gem': can't activate rack (~> 1.0.1, runtime), already activated rack-1.1.6. Make sure all dependencies are added to Gemfile. (Gem::LoadError)
from /var/www/rails_project/vendor/rails/actionpack/lib/action_controller.rb:34
from /var/www/rails_project/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /var/www/rails_project/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /var/www/rails_project/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /var/www/rails_project/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /var/www/rails_project/vendor/rails/railties/lib/console_app.rb:2
from /var/www/rails_project/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /var/www/rails_project/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /var/www/rails_project/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /var/www/rails_project/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /usr/local/rbenv/versions/1.8.7-p371/lib/ruby/1.8/irb/init.rb:254:in `load_modules'
from /usr/local/rbenv/versions/1.8.7-p371/lib/ruby/1.8/irb/init.rb:252:in `each'
from /usr/local/rbenv/versions/1.8.7-p371/lib/ruby/1.8/irb/init.rb:252:in `load_modules'
from /usr/local/rbenv/versions/1.8.7-p371/lib/ruby/1.8/irb/init.rb:21:in `setup'
from /usr/local/rbenv/versions/1.8.7-p371/lib/ruby/1.8/irb.rb:54:in `start'
from /usr/local/rbenv/versions/1.8.7-p371/bin/irb:13