I18n on Ruby on Rails, <and> is replaced by & gt; & lt; when not intended

I am creating locale files for internationalization in a rails application and have a url that I want to translate with tags included, e.g.

html.erb

<% = t (foo.bar.xxxx)%>

yml file

foo: bar: xxxx: "xxxx"

result

& lt; a href = "/info/index.html" & gt; xxxx </ a & gt;

which breaks my links. I don't have h on the ruby ​​part, so should this not work? Or do I just not need the html tags in the yml file?

Rails Version 3.0.1 Ruby Version - 1.8.7 p249

+6
source share
2 answers

Your HTML YAML keys must have the _html suffix:

 foo: bar: xxxx_html: "<strong>Some HTML Here</strong>" 

Doing this Rails will mean that the line has html_safe and will display HTML instead of converting it to &gt; and &lt; .

You need to reference it with the full key name, Rails does not automatically see the _html suffix when you call xxxx .

 <%= t 'foo.bar.xxxx_html' %> 
+28
source

Rails prevents injection by preventing the display of model data as actual markup. The raw function prevents this conversion.

whether

 <%= raw t(foo.bar.xxxx) %> 

Job?

+2
source

All Articles