Rails and HTML: how to keep form input formatting?

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

For instance:

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

Enter sample description

 -list1 -list2 -list3 

When I submit a form with this input, the next line is saved as the description field "-list1\r\n-list2\r\n-list3" . And when I output the description as follows:

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

This is the conclusion:

 -list1 -list2 -list3 

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

+4
source share
1 answer

Yes, you need to use HTML tags to create line breaks, as browsers do not respond to "\n" . The HTML layout view considers HTML tags, not textual content.

+5
source

Source: https://habr.com/ru/post/1490800/


All Articles