user2158382
user2158382

Reputation: 4510

Rails and HTML: How do i keep the formatting of a forms input

Hi I have a rails app with a simple HTML form. One of the fields called description is a text_area and I want to be able to display its input exactly how is was entered on the index page.

For example:

If someone enters input into the text area as a list. I want it to display exactly like that.

Sample description input

-list1
-list2
-list3

When I submit the form with this input, the following string is stored as the description field "-list1\r\n-list2\r\n-list3". And when I output description like so:

<div class='light panel radius bottom'>
  <%= job.description %>
</div>

This is the output:

-list1 -list2 -list3

I know if I wanted I could just parse the \r\n and replace it with a <br>. But that seems like a really ridiculous solution to something that should be easy.

Upvotes: 4

Views: 1056

Answers (1)

Mori
Mori

Reputation: 27779

Yes, you do need to use HTML tags to create line breaks, because browsers do not respond to "\n". HTML layout rendering looks at HTML tags, not text content.

Upvotes: 5

Related Questions