undefined method `[]’ for Enumerable

Wednesday, March 4th, 2009

Getting a strange error like this:

undefined method `[]' for #

It comes from an incompatibility between rails 2.0.2 and ruby 1.8.7 as noted here: http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg528878.html

To fix it you can do one of three things:

  1. Upgrade your app to rails 2.1.0 or greater
  2. Downgrade your version of ruby to 1.8.6 (not suggested)
  3. or place the following code in config/initializers/enurmerable_fix.rb
    unless '1.9'.respond_to?(:force_encoding)
    String.class_eval do
    begin
    remove_method :chars
    rescue NameError
    # OK
    end
    end
    end

Enjoy!

Leave a Comment