Ruby 1.8.7 Compability Issue

The symptom:

There is a problem accessing some parts of my Redmine installation. Apperantly, there is an incompatibility issues with ruby 1.8.7, that's why Redmine suggest Rails 2.0.2, ruby 1.8.7.  Oh, well... Veni, vidi, vici!

On the browser:

Document Error 500.

On the ruby environment (after activating debug symbol), the culprit:

ActionView::TemplateError (undefined method `length' for #) on line #2 of app/views/documents/_document.rhtml

The Answer:

Add the following line into $APPS_ROOT/config/environment.rb at the end of it:

module ActionView
  module Helpers
  module TextHelper
  def truncate(text, length = 30, truncate_string = "...")
  if text.nil? then return end
  l = length - truncate_string.chars.to_a.size
  (text.chars.to_a.size > length ? text.chars.to_a[0...l].join + truncate_string : text).to_s
  end
  end
  end
end

And restart any webserver you are using (fcgi, mongrel, etc) and hope to God!

Voila!

Thanks to a post by Giulio Turetta:

http://blog.sviluppoweb.eu/2008/11/26/undefined-method-length-for-enumerableenumerator-on-text_helperrb50in-truncate/

Comments

Popular Posts