[Ruby on Rails] Converting line breaks to br tags

Tadashi Shigeoka ·  Wed, December 19, 2012

Notes on a method to convert line breaks to br tags in Ruby on Rails.

Since simple_format adds unwanted p tags, creating a custom helper in ApplicationHelper would make you happy.

module ApplicationHelper
  # Convert line breaks to br tags
  def linebreak_to_br(text)
    text.gsub(/\r\n|\r|\n/, "
") end end

simple_format (ActionView::Helpers::TextHelper) - APIdock

That’s all from the Gemba.