Created
February 11, 2010 17:21
-
-
Save ybakos/301725 to your computer and use it in GitHub Desktop.
undefined method length for Enumerable Enumerator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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