我正在尝试在我的 erb 模板中呈现 unicode,例如:
我的种子:
Currency.create!(currency: 'USD', rate: 1.2805, title: 'U.S. Dollars', code: '\u0024', active: 1)
控制器:
@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
模板.erb:
<select>
<% @currencies.each do |node| %>
<option>
<%= node[:currency] %> - <%= node[:price] %>
</option>
<% end %>
</select>
我期望这个:
<option>USD - $32.01</option>
但我得到了原始的 unicode 输出:
<option>USD - \u002432.01</option>
我试过了:
添加 utf8 编码元属性。添加: <%# encoding: utf-8 %> 到我的模板。并在字符串上使用 .html_safe 。