我的 View 中有一个变量在屏幕上打印为
<%= comment.comment %>
但是输出有很多换行符(\n
)。
每当我们有一个带有 comment.comment
输出的 \n
时,我如何让它实际打印新行?
最佳答案
试试这个:
<%= comment.comment.gsub(/\n/, '<br />') %>
否则你也可以使用simple_format
.这里:
<%= simple_format(comment.comment) %>
关于ruby-on-rails - 在文本变量中使用/n 添加新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30566516/