使用 HAML 在 simple_form 中将 Unicode 字符转义为纯文本
Unicode character being escaped as plain text in simple_form with HAML
因为样式输入很困难,所以我将输入隐藏在 simple_form 中并用标签欺骗它们。
我希望提交按钮的标签显示一个 unicode 字符,但将它放在第二个参数中会将其转义为纯文本。
使用 HAML:
= simple_form_for @post, html: {multipart: true} do |f|
= f.file_field :file, {id: "file"}
= f.button :submit, {id: "submit"}
= label_tag(:file, "upload file")
= label_tag(:submit, "↑")
显示 "upload file, ↑"
如果不想Rails自动转义,可以使用raw(stringish)
辅助方法
所以应该是:
= simple_form_for @post, html: {multipart: true} do |f|
= f.file_field :file, {id: "file"}
= f.button :submit, {id: "submit"}
= label_tag(:file, "upload file")
= label_tag(:submit, raw("↑"))
仅供参考,如果数据来自用户输入,则不建议这样做。
因为样式输入很困难,所以我将输入隐藏在 simple_form 中并用标签欺骗它们。
我希望提交按钮的标签显示一个 unicode 字符,但将它放在第二个参数中会将其转义为纯文本。
使用 HAML:
= simple_form_for @post, html: {multipart: true} do |f|
= f.file_field :file, {id: "file"}
= f.button :submit, {id: "submit"}
= label_tag(:file, "upload file")
= label_tag(:submit, "↑")
显示 "upload file, ↑"
如果不想Rails自动转义,可以使用raw(stringish)
辅助方法
所以应该是:
= simple_form_for @post, html: {multipart: true} do |f|
= f.file_field :file, {id: "file"}
= f.button :submit, {id: "submit"}
= label_tag(:file, "upload file")
= label_tag(:submit, raw("↑"))
仅供参考,如果数据来自用户输入,则不建议这样做。