Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8435057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:49:30+00:00 2026-06-10T06:49:30+00:00

I have a text field in my model called ‘about’, which I’m trying to

  • 0

I have a text field in my model called ‘about’, which I’m trying to display on a show page, but none of the line breaks are showing up properly.

I’ve tried a number of things, but the code I finally landed on is:

<%= (h @template.about).gsub("\n", "<br />") %>

Unfortunately, Rails seems to be escaping the desired HTML and outputting these line breaks as

Thanks for the fish, guys! Not like I wanted it, but... uh... thanks? &lt;br /&gt;

How can I properly convert the text field’s “\n” linebreaks into actual linebreak HTML? I’ve already tried simple format as well, to no avail…

I’m using Rails 3, and the first few lines of ‘about’ are:

Thanks for the fish, guys! Not like I wanted it, but… uh… thanks?

“I’ll be the judge of that,” he said!
And now, more useless copy so I can isolate that weird bud that Amanda found.
Wait! I meant ‘weird bug…’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:49:32+00:00Added an answer on June 10, 2026 at 6:49 am

    try

    <%= simple_format @template.about %>
    

    http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-simple_format

    It works for me :-\

    1.9.3p194 :017 > str = "Thanks for the fish, guys! Not like I wanted it, but... uh... thanks? 
    1.9.3p194 :018"> \"I'll be the judge of that,\" he said! 
    1.9.3p194 :019"> And now, more useless copy so I can isolate that weird bud that Amanda found. 
    1.9.3p194 :020"> Wait! I meant 'weird bug..."
     #=> "Thanks for the fish, guys! Not like I wanted it, but... uh... thanks? \n\"I'll be the judge of that,\" he said! \nAnd now, more useless copy so I can isolate that weird bud that Amanda found. \nWait! I meant 'weird bug..."
    
    
    1.9.3p194 :021 > simple_format str
     #=> "<p>Thanks for the fish, guys! Not like I wanted it, but... uh... thanks? \n<br />\"I'll be the judge of that,\" he said! \n<br />And now, more useless copy so I can isolate that weird bud that Amanda found. \n<br />Wait! I meant 'weird bug...</p>"
    

    or using gsub

    1.9.3p194 :022 > str.gsub("\n", "<br />") 
     #=> "Thanks for the fish, guys! Not like I wanted it, but... uh... thanks? <br />\"I'll be the judge of that,\" he said! <br />And now, more useless copy so I can isolate that weird bud that Amanda found. <br />Wait! I meant 'weird bug..." 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails Model called Events which has as field/attribute called :description. I
I have model Article it has field title with some text that may contain
I have a text field. If it has wrong values then it may show
I've got a user model which contains a field called, lets say, text1. In
I have a model called Company, and in the Show view have the following:
For example: In my table I have text field with following text: The quick
i have a text field in Contact screen and the user need to enter
I have a text field that is near the bottom of the screen. When
I have a text field and am looking to have if be valid for
I have a text field that is a date, although sometimes it also has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.