html - 为表达式内的 Ruby 字符串中的单词添加文本样式
问题描述
我正在尝试在这个 ruby 字符串中设置一些粗体字,它位于 ruby 表达式内部,它位于 html 元素内部。我希望 current_user.email 文本为粗体,而不是其余文本。
<li>"><%= link_to "Sign out of #{current_user.email}", sign_out_path %></li>
我该怎么办?
解决方案
您可以使用raw
<li><%= link_to raw("Sign out of <strong>#{current_user.email}</strong>"), sign_out_path %></li>
这是文档:https ://edgeguides.rubyonrails.org/active_support_core_extensions.html#output-safety
推荐阅读
- d3.js - 如何在不丢失信息或失真的情况下将geojason文件转换为topojson?
- git - 将源代码从 TFS git 移动到本地 git
- python - pandas:在特定时间窗口中选择行
- spring - Spring Boot如何从测试中排除某些类
- python - 如何更改 QDialog 中的默认按钮行为
- add-in - Enteprise Architect 元素 MiscData(0) 更改 (PDATA1)
- emacs - 在 Windows bash 上查找 .emacs 文件
- r - 根据列中的值拆分行
- javascript - 将选择选项清除并重置为默认值在 Jquery 中不起作用
- angular - Angular 2+ 包通信