HTML objects in Rails link_to

How to embed HTML objects in link_to rails?

For example, & # 10029 will give you a star symbol, how can I insert it into a quote?

For instance,

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

Thank!

+4
source share
2 answers

Try the following:

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

Use this method to escape:

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

Do not use html_safe () unless you are sure your string is non-zero. Instead, use the raw () method, which will not throw an exception on nil.

Api Rails raw ()

+3
source

Source: https://habr.com/ru/post/1569044/


All Articles