Reputation: 2450
In my view I want to display some right double angle quotes in my link.
Before Rails 3, this worked:
<%= link_to "» #{@category.name}", some_path %>
Now what should I do if I want to specify the »
as html_safe but not the rest of the link's text?
In other words I do not want to do this:
<%= link_to "» #{@category.name}".html_safe, some_path %>
I do not want the @category.name
treated as html_safe.
This produces the desired result:
<%= link_to "»".html_safe + " #{@category.name}", some_path %>
However, if I do this:
<%= link_to "#{@category.name}" + "»".html_safe, some_path %>
The output of the angle quotes is not treated as safe. I see »
on my page and not ».
Why?
I tried extracting "»".html_safe
to a helper method with the same results.
Is there a way to easily designate hard coded text/symbols as HMTL safe in Rails 3?
Thanks.
Upvotes: 3
Views: 1231
Reputation: 33752
you need to make sure that the whole string is html_safe...
I'd recommend to try this:
"» #{h @cagegory.name}".html_safe
Upvotes: 0
Reputation: 7714
In this situation I often explicitly escape the unsafe part:
"» #{h @category.name}".html_safe
Upvotes: 3