undefined method `length’ for Enumerable Enumerator on text_helper.rb:50:in `truncate’

With rails 2.0.2 and ruby 1.8.7 you can find this error using rails truncate helper

To solve this problem, paste this code in your enviroment.rb (eof).

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

Have a nice day!


Tags: , , , ,

About Autore

Amo internet e le opportunità che ci offre. Grazie anche a te, che fai parte di questo mondo fantastico.

18 responses to “undefined method `length’ for Enumerable Enumerator on text_helper.rb:50:in `truncate’”

  1. jpmrblood says :

    Thank you.

    Fixed my Redmine installation havoc with this enlightenment.

  2. Shtirlic says :

    Thank you, helped with redmine also

  3. albertux7 says :

    Thanks so much this code make posible run some old software based on ruby on rails thanks a lot man

  4. caffeine says :

    Woo, that fixed it. Thank you 😉

  5. Mark says :

    Thank you for sharing this, nice quick fix.

  6. Ashwanth says :


    Nice tip.


  7. devicebusy says :

    Thanks alot, on Ubuntu 9.04 (gems from src) this fix work ok.

  8. Ben says :

    I was having the same symptom with Warehouse and although I don’t know how to get the error this fix worked for it. Thanks!

  9. Phil says :

    Thanks for posting the fix.

  10. Priya Saini says :

    It really helped me.

  11. Nick Moore says :

    Thanks, fixed a problem we were having with Redmine 0.7.3 on Ubuntu 9.10 … at least long enough for us to upgrade to 10.04 in due course anyway.

  12. LorencoHix says :

    Did you know that USA and Europe blocked Wikileaks? What do you think about it?
    Thank you

  13. hadrian says :

    Thank you for sharing this, nice quick fix.

  14. Martin says :


  15. Julien Desrosiers says :

    I am working on an old rails 2.0.2 project and i just wanted to say: Thanks a lot!

  16. Johnson says :

    Thank you so much..!

  17. Billy says :

    Just to say, THANK YOU!!!!!!!!!!!!!!!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: