我正在尝试创建一个包装d3.js的gem,可以在https://github.com/iblue/d3-rails找到Source
所以当我在我的Gemfile中包含这个gem时
gem "d3-rails", :git => "git://github.com/iblue/d3-rails.git"
当我在我的application.js中包含javascript:
//=require d3
然后我的资产编译失败,我编译的application.js只包含
throw Error("Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT")
我正在使用Rails 3.1.3和ruby-1.9.3-p125。 jQuery使用完全相同的gem结构,它的工作原理。我做错了什么?
修改:
我也看到了这个问题:Ruby 1.9 throwing javascript encoding error。这不适用于此,我的文件是有效的UTF-8:
ruby-1.9.3-p125 :001 > d = File.read("./d3.js")
=> [...]
ruby-1.9.3-p125 :002 > d.encoding
=> #<Encoding:UTF-8>
ruby-1.9.3-p125 :003 > d.valid_encoding?
=> true
编辑2 :
我还尝试在config/environment.rb
中插入一些伏都教。它不起作用:
# -*- encoding : utf-8 -*-
# Load the rails application
require File.expand_path('../application', __FILE__)
# --------- VOODOO BEGINS HERE -----------------
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
# --------- END VOODO --------------------------
# Initialize the rails application
Ratecode::Application.initialize!
答案 0 :(得分:9)
是来自WEBrick服务器的错误还是其他什么? rake assets:precompile
有用吗? (不要忘记清除资产后)
如果后者失败,请仔细检查$ LANG环境变量的值是UTF-8(带env
)。如果rake任务有效,但应用程序失败,那么它可能是服务器env vars。