📜  如何让新行显示在 Rails 中 - Ruby 代码示例

📅  最后修改于: 2022-03-11 15:04:45.845000             🧑  作者: Mango

代码示例1
<%= obj.description %>
Even though your value may be "One  \t  \n  \n  Two", it will show up on the screen as "One Two".

To get those new line characters to actually separate the lines when displayed, you'll need to convert them to HTML before rendering:

<%= obj.description.gsub(/\n/, '
') %> Of course, if users are entering data that will be included in your HTML, you should be escaping the values to protect against XSS. If new lines are the only thing you need to support, it should be as simple as this: <%= h(obj.description).gsub(/\n/, '
') %>