Tag Archive | truncate helper error
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!