you are in: codestackercodes [RSS]truncate text at a word boundry

truncate text at a word boundry Delicious Email

show/hide lines
   1  # in application_helper
   2  
   3  def snippet(text, wordcount, omission)
   4   text.split[0..(wordcount-1)].join(" ") + (text.split.size > wordcount ? " " + omission : "")
   5  end
   6  
   7  
   8  # example
   9  
  10  snippet(@post.body, 50, "#{link_to "More...", @post}")
created by leozera — 20 April 2009 — get a short url — tags: helper rails ruby embed

Comments



We dont send spam :)

If checked, it's highlights your comment
simple_captcha.jpg
Are you a human? Type the code from the image