Skip to content

Instantly share code, notes, and snippets.

@maxivak
Last active March 2, 2016 13:41
Show Gist options
  • Save maxivak/c6266125d042ef7a04ed to your computer and use it in GitHub Desktop.
Save maxivak/c6266125d042ef7a04ed to your computer and use it in GitHub Desktop.
Rails sanitize html

Sanitize HTML, replace end lines with BR

view:

= nl2br(sanitize(message, tags: [])).html_safe

controller:

nl2br(ActionView::Base.full_sanitizer.sanitize(message)).html_safe

helper:

# app/helpers/message_helper.rb

  def nl2br(s)
    s.gsub(/\n/, '<br>')
  end


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment