【问题标题】:ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT) in RailsRails 中的 ActionView::Template::Error(不兼容的字符编码:UTF-8 和 ASCII-8BIT)
【发布时间】:2015-11-05 09:54:58
【问题描述】:

尝试下面的代码然后error generate

我发现了许多相同的问题,但仍然没有解决。

 <% product_prices = []
             product.product_prices.each{|product_price| product_prices << number_to_currency(product_price.price.to_f, :unit => "£").force_encoding(Encoding::UTF_8)}
          %>

有朋友有answertrick吗?

谢谢

【问题讨论】:

    标签: ruby-on-rails utf-8 utf


    【解决方案1】:

    在强制编码之前先转换为字符串。试试下面的代码:

    <% product_prices = [] %>
    <% product.product_prices.collect{|product_price| product_prices << number_to_currency(product_price.price.to_f, :unit => "£").to_s.force_encoding(Encoding::UTF_8)} %>
    

    【讨论】:

    • 您是否尝试将 .each 更改为 .collect ?你有没有用&lt;% %&gt;分隔每一行。我更新了上面的代码。
    猜你喜欢
    • 2011-07-10
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    • 2016-02-12
    • 2011-05-26
    • 2011-12-14
    • 1970-01-01
    • 2011-07-14
    相关资源
    最近更新 更多