Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%= message.content %>
- truncate("Once upon a time in a world far far away", :length => 17, :separator => ' ')
- # => "Once upon a..."
- class String
- def words_limit(limit)
- string_arr = self.split(' ')
- string_arr.count > limit ? "#{string_arr[0..(limit-1)].join(' ')}..." : self
- end
- end
- text = "aa bb cc dd ee ff"
- p text.words_limit(3)
- # => aa bb cc...
- # Message helper
- def content_excerpt(c)
- return unlessc
- c.split(" ")[0..4].join + "..."
- end
- # View
- <%= message.content_excerpt %>
- # Message helper
- def content_excerpt(c)
- return unless c
- truncate(c, :length => 20)
- end
Add Comment
Please, Sign In to add comment