Skip to content

Instantly share code, notes, and snippets.

@ybakos
Created February 11, 2010 17:21
Show Gist options
  • Select an option

  • Save ybakos/301725 to your computer and use it in GitHub Desktop.

Select an option

Save ybakos/301725 to your computer and use it in GitHub Desktop.
undefined method length for Enumerable Enumerator
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment