Reputation: 12218
I'm trying to render unicode in my erb template, e.g:
My seed:
Currency.create!(currency: 'USD', rate: 1.2805, title: 'U.S. Dollars', code: '\u0024', active: 1)
Controller:
@currencies = []
Currency.where(:active => TRUE).each do |node|
c = node.rate * 25
c = number_to_currency(c, :precision => 2, :unit => node.code)
@currencies.push(:currency => node.currency, :price => c)
end
Template.erb:
<select>
<% @currencies.each do |node| %>
<option>
<%= node[:currency] %> - <%= node[:price] %>
</option>
<% end %>
</select>
I expect this:
<option>USD - $32.01</option>
But I get the raw unicode output:
<option>USD - \u002432.01</option>
I've tried:
Adding a utf8 encoding meta attribute. Adding: <%# encoding: utf-8 %> to my template. And using .html_safe on the string.
Upvotes: 0
Views: 1477
Reputation: 43298
It's because you're using single quotes in your seed. It should be double quotes:
"\u0024" # => "$"
'\u0024' # => "\\u0024"
Upvotes: 2