Search code examples
htmlcssruby-on-railsrubystyling

Adding Text Styling to Words in a Ruby String Inside of an Expression


I'm trying to style some words bold inside of this ruby string, which is inside of a ruby expression, which is inside of an html element. I want the current_user.email text to be bold, but not the rest of the text.

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

How would I go about this?


Solution

  • You can use raw

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

    Here is the docs : https://edgeguides.rubyonrails.org/active_support_core_extensions.html#output-safety