编程语言
首页 > 编程语言> > javascript – 具有外部gem的资产管道编码问题(UTF-8与ASCII-8BIT)

javascript – 具有外部gem的资产管道编码问题(UTF-8与ASCII-8BIT)

作者:互联网

我正在尝试创建一个包装d3.js的gem,Source可以在https://github.com/iblue/d3-rails找到

所以当我在我的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中插入一些voodoo.这是行不通的:

# -*- 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!

解决方法:

来自WEBrick服务器的错误还是其他什么? rake资产:预编译工作? (不要忘记清除资产后)

如果后者失败,请仔细检查$LANG环境变量的值是UTF-8(使用env).如果rake任务有效但应用程序失败则可能是服务器env vars.

标签:javascript,ruby-on-rails,rubygems,asset-pipeline,ruby-on-rails-3-1
来源: https://codeday.me/bug/20191008/1869780.html