4

How do I insert HTML entities in a rails link_to?

For instance &#10029 will give you a star character, how do I insert this inside a quote?

For example,

<%= link_to " &#10029 Home", root_path %>

Thanks!

user2085143
  • 4,162
  • 7
  • 39
  • 68

2 Answers2

16

Try this:

<%= link_to raw("&#10029 Home"), root_path %>
webster
  • 3,902
  • 6
  • 37
  • 59
4

Use this method for escape:

<%= link_to raw("&#10029 Home"), root_path %>

Don’t use html_safe() unless you’re sure your string isn’t nil. Instead use the raw() method, which wont raise an exception on nil.

Api Rails raw()