[RUBY] When continuous line breaks are displayed on the screen, the line breaks are combined into one.

1) Background </ font>

See the "Content Registration" section in the image below. There are 9 lines in total.

If you register this and display it with the ** simple_format ** </ font> method on another screen, it will be as follows.

How can I get the number of lines as registered? I thought about countermeasures.

2) Environment </ font>

item Contents
OS.Catalina v10.15.4
Ruby v2.5.1
Ruby On Rails v5.2.4.3

3) Contents </ font>

** Correspondence 1) Create a helper method. ** ** I also saw other people's articles, but I made a helper as follows.

application_helper.rb


1 module ApplicationHelper
2   #In the case of consecutive line feed codes, the line feed tag is explicitly inserted because it is escaped.
3   def br(str)
4     str.gsub(/\r\n|\r|\n/, "<br />").html_safe
5   end
6 end

Use this helper by calling it as follows when displaying. Making it a helper is convenient because the cost of making it is low.

erb:test.html.erb


1   <div class="krown-value">
2     <%= br(@knowledge.content) %>
3   </div>

It is now displayed in 9 lines like this.

that's all.