Line breaks in the entered text are not displayed in view

Overview

I will share the solution when the text entered in text_area contains line breaks, but the line breaks are not reflected when I look at the post list.

For example, in the post message


xxx yyy zzz


When I intended to enter it, but when I check it in the post list


xxx yyy zzz


It is a coping method when it becomes.

Conclusion

index.html.erb


<%= post.message %>

The part that was

index.html.erb


<%= simple_format(post.message) %>

Let's say.

What is simple_format?

simple_format is a helper used to display text containing newline characters on the browser. A brief summary of the features of simple_format.

Enclose the string in <p> Add <br /> to line breaks Add </ p> <p> for consecutive line breaks

(See other articles)

Recommended Posts

Line breaks in the entered text are not displayed in view
How to display the text entered in text_area in Rails with line breaks
The problem that the contents of params are completely displayed in the [Rails] view
[Rails / simple_format] Helper method that reflects line breaks entered in the form
When continuous line breaks are displayed on the screen, the line breaks are combined into one.
When the project is not displayed in eclipse
[Problem solving] Tomcat: Settings after line breaks in "Java Options" are not reflected
[Error] The app is not displayed in the production environment
[Ruby On Rails] How to use simple_format to display the entered text with line breaks
How to check if the characters entered in the Swift Text Field are email addresses
If the submodule assets are not found in the Play Framework
[Development log ⑬] Do not let 0 be entered in the form !!
Check if Ethereum transactions are not included in the block
What to do when the changes in the Servlet are not reflected
What are the rules in JUnit?
The difference between puts and print in Ruby is not just the presence or absence of line breaks
[Rails] About the error that the image is not displayed in the production environment
[Cloud9] Yay! You ’re on Rails! Is not displayed in the rails tutorial
must not return in the for statement
Image is not displayed in production environment
Rails6: Extract the image in Action Text
The list of installed apps is not displayed in getPackageManager (Android11 ​​/ API level 30)