Thursday, July 15, 2010

Rails on Debian

Ran into a strange issue while debugging a Rails app that I am working on. I finally found the exact problem and issue here http://wiki.github.com/radiant/radiant/undefined-method-for-enumerable

Turns out that
the error comes from an incompatibility between Ruby 1.8.7 and Rails 2.0.2. Ruby 1.8.7 has String#chars and returns an Enumerator object, but Rails 2.0.2 expects an ActiveSupport::Multibyte::Chars object.
Which is pointed out here http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg528878.html

Putting this in your environment.rb fixes the issue
unless '1.9'.respond_to?(:force_encoding)
  String.class_eval do
    begin
      remove_method :chars
    rescue NameError
      # OK
    end
  end
end

No comments: