This project is archived and is in readonly mode.
undefined method `length' for Enumerable when calling truncate method
-
Peter Wagenet
If your fix works, make a patch with some tests to verify it. If you don't know where to start, check out: http://rails.lighthouseapp.com/p...
-
Ronald de Gunst
truncate takes an option hash instead of separate length and omission arguments See http://www.rubyonrails.org/depre... for details.
-
Gregor Magdolen
@peter: thanks, im new to ruby and rails and i found bug by "accident", but i'll try my best to make a patch.
@ronald: can you be more specific? I can't find enough information on site you provided. I also believe I have installed latest stable release of rails (installed via gem)
-
Peter Wagenet
Gregor, it seems we often run into these sorts of things by accident :) Good luck with the patch. I can take a look at it for you once you get it up. Let me know if you have any difficulties.
-
Boo Yah
Peter, I ran into the same issue but solved the problem by eliminating the calls to the 'chars' function:
def truncate(text, length = 30, truncate_string = "...") if text.nil? then return end l = length - truncate_string.length (text.length > length ? text[0...l] + truncate_string : text).to_s end -
Peter Wagenet
@Boo Yah: You'll want to make sure that's the right solution. The chars method is for dealing with Unicode, so removing that call may make the truncate method no longer Unicode safe.
-
tigris
Gregor,
The issue is that 1.8.7 ruby introduced it's own chars() method onto the String object, overwriting ActiveSupport's attempts to patch it's own chars() method on there.
I believe if you roll back to ruby 1.8.6, your problem will go away.
I am unsure if it is fixed in newer versions of rails, I am about to go and update my rails now and make sure it all works on 1.8.6 before I attempt to upgrade ruby again.
regards, Danial
-
tigris
Edit: looks fixed in current rails
http://github.com/rails/rails/co...
09/21/08: Change all calls to String#chars to String#mb_chars.
-
iGEL
- Tag changed from actionpack, bug, enumerable, helper to actionpack, activesupport, bug, enumerable, helper, multibyte
I can verify this problem. "Hello".chars is returning an Enumerable::Enumerator on Rails 2.2 RC1 and 2 with ruby 1.8.7. With Rails 2.1.2/Ruby 1.8.7 it worked fine.
Using Ubuntu 8.10 here.
"Hello".chars.downcase NoMethodError: undefined method
downcase' for #<Enumerable::Enumerator:0xb6809e84> -
iGEL
After 2 hours of searching for a bug in Rails, I've realized, that I've should have read tigris completely. Sorry...
-
DHH
- Assigned user set to Michael Koziarski
-
Michael Koziarski
- State changed from new to resolved
2.1.x doesn't support ruby 1.8.7.
Either downgrade to 1.8.6 or upgrade rails to 2.2 RC2
-
Nathan de Vries
Can this not be solved (albeit hackishly) by dropping the following into an initializer?
class String def chars ActiveSupport::Multibyte::Chars.new(self) end alias_method :mb_chars, :chars endI'm using that trick to get Mephisto + Rails v2.0.5 running under 1.8.7.
-
Micah Wedemeyer
Nathan, I could kiss you. Your little snippet was enough to get me up and running while I search for a way to migrate a legacy app to something new.