betweenGo

Formatting Text

by Frank Kim on Oct.14, 2008, under Ruby on Rails

For text fields one typically wants to allow some HTML tags, add support for link breaks and even auto link URL’s and emails.

This method which I got from this forum thread, Adding a line break … safely, does all of this and is a must add to my application_helper.rb.

def format_content(content)
  # allow only tags specified in tags options, likewise in attributes
  content = sanitize(content, :tags => %w(b strong i em img), :attributes => %w(src))

  # add support for line breaks
  content = simple_format(content)

  # auto link URL's and emails
  content = auto_link(content, :all, :target => '_blank')

  return content
end


  • Share/Bookmark

Related posts:

  1. Mysterious dspel:include problem with flush=true
  2. Submitting an ATG Form Using a Text Link
  3. You Used Ruby to Write WHAT?!
  4. Perforce Adding a Directory Tree

:

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!