Ruby / Rails - Is there an easy way to make hardcoded html_safe HTML characters?

In my opinion, I want to display some quotes with a right angle in my link.

Before Rails 3, this worked:

<%= link_to "&raquo; #{@category.name}", some_path %>

Now what should I do if I want to specify &raquo;as html_safe, but not all the link text?

In other words, I do not want to do this:

<%= link_to "&raquo; #{@category.name}".html_safe, some_path %> I do not want to @category.namebe considered as html_safe.

This gives the desired result:

<%= link_to "&raquo;".html_safe + " #{@category.name}", some_path %>

However, if I do this:

<%= link_to "#{@category.name}" + "&raquo;".html_safe, some_path %>

The output of angle quotes is not considered safe. I see &raquo;on my page, not & raquo ;.

Why?

I tried to extract a "&raquo;".html_safehelper method with the same results.

Is there a way to easily label hardcoded text / characters as safe HMTL in Rails 3?

Thank.

+3
2

:

"&raquo; #{h @category.name}".html_safe
+3

, html_safe...

:

   "&raquo; #{h @cagegory.name}".html_safe
0

All Articles