首页 > 解决方案 > 为表达式内的 Ruby 字符串中的单词添加文本样式

问题描述

我正在尝试在这个 ruby​​ 字符串中设置一些粗体字,它位于 ruby​​ 表达式内部,它位于 html 元素内部。我希望 current_user.email 文本为粗体,而不是其余文本。

<li>"><%= link_to "Sign out of #{current_user.email}", sign_out_path %></li>

我该怎么办?

标签: htmlcssruby-on-railsrubystyling

解决方案


您可以使用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


推荐阅读