Skip to content

Instantly share code, notes, and snippets.

@tomeduarte
Created September 6, 2011 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomeduarte/1197275 to your computer and use it in GitHub Desktop.
Save tomeduarte/1197275 to your computer and use it in GitHub Desktop.
rails helper to truncate a string to max 40 characters, without breaking words.
def truncate_name(name)
name.gsub(/^(.{40}[\w.]*)(.*)/) {$2.empty? ? $1 : $1 + '...'}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment