【问题标题】:Adding Text Styling to Words in a Ruby String Inside of an Expression为表达式内的 Ruby 字符串中的单词添加文本样式
【发布时间】:2019-04-13 14:35:16
【问题描述】:

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

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

我该怎么办?

【问题讨论】:

    标签: html css ruby-on-rails ruby styling


    【解决方案1】:

    你可以使用raw

    &lt;li&gt;&lt;%= link_to raw("Sign out of &lt;strong&gt;#{current_user.email}&lt;/strong&gt;"), sign_out_path %&gt;&lt;/li&gt;

    这里是文档:https://edgeguides.rubyonrails.org/active_support_core_extensions.html#output-safety

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多