我正在尝试创建一个包装d3.js的gem,源代码可以在https://github.com/iblue/d3-rails上找到
所以当我把这个宝石包含在我的Gemfile中
gem "d3-rails", :git => "git://github.com/iblue/d3-rails.git"当我将javascript包含在我的application.js中时:
//=require d3然后我的资产编译失败,我编译的application.js只包含
throw Error("Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT")我使用Rails 3.1.3和ruby-1.9.3-p 125。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!发布于 2012-03-08 11:30:39
是来自WEBrick服务器的错误还是其他的错误?rake assets:precompile有效吗?(别忘了事后清理资产)
如果后者失败,请再次检查$LANG环境变量的值为UTF-8 (使用env)。如果rake任务能够工作,但是应用程序失败了,那么它可能是服务器env。
https://stackoverflow.com/questions/9525381
复制相似问题