ruby-on-rails - en.yml 中的新行不会在 html 页面上呈现
问题描述
在 en.yml 我有带有新行的字符串。当它们在 html 页面上呈现时,新行会消失——它被呈现为单行。
我的en.yml:
test: |+
Something fdsafdsfd
fdsafdsfd
解决方案
\n
YAML为该test
键返回一个字符串。如果你想在 html 中显示它,你需要将新行转换为正确的 html 标签。您可以为此使用simple_format助手:
simple_format("foo\nbar") # => "<p>foo\n<br />bar</p>"
simple_format("foo\n\nbar") # => "<p>foo</p>\n\n<p>bar</p>"
推荐阅读
- mysql - 如何在我的组合框 vb.net 上使用月份过滤我的表格
- python - Python - 如何过滤数据框以仅保留一种产品的订单号?
- sql - 在 SQL 中将不同的日期格式转换为相同的日期格式?
- node.js - 在 Ubuntu 上用 Wine 运行节点
- javascript - 是什么导致此错误不断出现以及如何防止它继续发生
- database - 我如何知道数据是否在 iotdb 中刷新
- python - 在 python 数据框中拆分 2 列或更多列的字符串内容并附加到 Python 中的新行
- python - 反向引用组在 python 正则表达式中不起作用
- swift - iOS并发:如何使用信号量而不是屏障?
- tkinter - 将特定命令分配给新创建的按钮