There's enough for everyone

गते गते पारगते पारसंगते बोधि स्वाहा गते गते पारगते पारसंगते बोधि स्वाहा

Rails 2.3 With Ruby 2.0

So of course we want to run our rails-2.3.17 apps on ruby-2.0, cos it’s faster and damn the consequences. But there’s a problem with Gem.source_index:

1
rails-2.3.17/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module (NoMethodError)

Fortunately a fix is relatively easy. This monkey-patch works in at least one real 2.3.17 application, although it ignores vendor gems. It has not been tested extensively and may cause your rails app to turn into a DSL for generating backtraces.

config/environment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

# monkey patch for 2.0. Will ignore vendor gems.
if RUBY_VERSION >= "2.0.0"
  module Gem
    def self.source_index
      sources
    end

    def self.cache
      sources
    end

    SourceIndex = Specification

    class SourceList
      # If you want vendor gems, this is where to start writing code.
      def search( *args ); []; end
      def each( &block ); end
      include Enumerable
    end
  end
end

Rails::Initializer.run do |config|
  config.gem 'haml'
  # etc
  # maybe some more
  # and so on...

  # Note that iconv is a gem in ruby-2.0
  config.gem 'iconv' if RUBY_VERSION >= "2.0.0"

  # some other config stuff
  # and some more
  # and a little more...
end

Comments