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
      end
    end
  end
end

Have a nice day!

Tags: , , , ,

Unknown's avatar

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's avatar
    jpmrblood says :

    Thank you.

    Fixed my Redmine installation havoc with this enlightenment.

  2. Shtirlic's avatar
    Shtirlic says :

    Thank you, helped with redmine also

  3. albertux7's avatar
    albertux7 says :

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

  4. caffeine's avatar
    caffeine says :

    Woo, that fixed it. Thank you 😉

  5. Mark's avatar
    Mark says :

    Thank you for sharing this, nice quick fix.

  6. Ashwanth's avatar
    Ashwanth says :

    Hey…

    Nice tip.

    Thanks!

  7. devicebusy's avatar
    devicebusy says :

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

  8. Ben's avatar
    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's avatar
    Phil says :

    Thanks for posting the fix.

  10. Priya Saini's avatar
    Priya Saini says :

    Thanks.
    It really helped me.

  11. Nick Moore's avatar
    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's avatar
    LorencoHix says :

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

  13. hadrian's avatar
    hadrian says :

    Thank you for sharing this, nice quick fix.

  14. Martin's avatar
    Martin says :

    Thanks!

  15. Julien Desrosiers's avatar
    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's avatar
    Johnson says :

    Thank you so much..!

  17. Billy's avatar
    Billy says :

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

Leave a reply to Mark Cancel reply