Strange error after upgrading from 1.3.1 to 1.4.0

Hi all,
i’m migrating my rails app from jruby 1.3.1 to 1.4.0 (linux)
and when running tests and entering a page where truncate helper is used
i have an exception :
NoMethodError: undefined method `length’ for #<Enumerable::Enumerator
so after checking file text_helper.rb my rails (1.2.6) version it
turns out that there is a line:
def truncate(text, length = 30, truncate_string = “…”)
if text.nil? then return end
l = length - truncate_string.chars.length
text.chars.length > length ? text.chars[0…l] + truncate_string
: text
end

also in jirb
#"…".chars.length
throws an exception,
so this method can’t possibly work well - am i right?

Then again in jruby 1.3.1 in jirb
#"…".chars.length
throws Exception complaining about chars - no such method (windows)

Obviously i don’t see something important because it should not work
in 1.3 and in 1.4

Any ideas?

Best greetings,
Paweł Wielgus.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi Paweł,

I guess, rails provides its own version of #chars, which started to
clash with MRI’s 1.8.7 method with the same name, so #chars in rails
is deprecated.

Thanks,
–Vladimir

2009/11/25 PaweÅ‚ Wielgus [email protected]:

    text.chars.length > length ? text.chars[0…l] + truncate_string : text

  http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi Vladimir,
thank You for your reply.

So if would like to correct it some how,
i would need to provide a patch to rails 1.2.6?

Best gretings,
Paweł Wielgus.

2009/11/25 Vladimir S. [email protected]:

Hi all,
   end
Obviously i don’t see something important because it should not work
  http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi guys,
in the end i have implemented my own truncate helper,
so all my tests pass now and my app is running great on jruby 1.4.0.
Thank You for your advices.

Best greetings,
Pawel Wielgus.

2009/11/25, Dhussa, Varun [email protected]:

begin
Regards

and when running tests and entering a page where truncate helper is used

in 1.3 and in 1.4


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi,

I had run into the same problem while upgrading to ruby 1.8.7 with the
same rails platform. There are 2 things you can do:

  1. Include the mb_chars class as a plugin into Rails 1.2.6
  2. Remove the ruby chars implementation
    In your environment.rb add:
    Unless ‘1.9’.respond_to?(:force_encoding)
    String.class_eval.do
    begin
    remove_method :chars
    rescue NameError
    #No prob!
    end
    end

The first will require more work but is a better bet from a future
migration perspective and that’s what I’ve done. You will also need to
change all chars calls to mb_chars.

Regards
Varun