views:

21

answers:

2

I am creating locale files for internationalization in a rails app, and have a url that I want translated with tags included , for example

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 do not have an h on the ruby part, so shouldn't this work? Or should I just not have html tags within the yml file?

Rails version is 3.0.1 Ruby version is 1.8.7 p249

+2  A: 

Rails is preventing injection attacks by preventing model data from being displayed as actual markup. The raw function prevents that conversion.

Does

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

work?

Bryan Marble
This worked just as well as the other one, was not aware of the raw method. This could come in handy some time, thanks for the info.
Saifis
+2  A: 

Your HTML YAML keys need to have a _html suffix:

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

Doing this Rails will mark the string has html_safe and will render out the HTML instead of converting it to &gt; and &lt;.

You need to reference it with the full key name as well, Rails doesn't automatically see the _html suffix when you call xxxx.

<%= t 'foo.bar.xxxx_html' %>
Garrett
this worked beautifully, the prefix is pretty handy for identification too, thanks.
Saifis