资产流水线编码问题(UTF-8与ASCII-8BIT)与外部宝石 [英] Asset pipeline encoding problems (UTF-8 vs. ASCII-8BIT) with external gem

查看:152
本文介绍了资产流水线编码问题(UTF-8与ASCII-8BIT)与外部宝石的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个封装d3.js的源码,可以在 https: //github.com/iblue/d3-rails



因此,当我将这个宝石包含在我的Gemfile中时

  gemd3-rails,::git => git://github.com/iblue/d3-rails.git

当我包含在我的application.js中的JavaScript:

  // =需要d3 

然后我的资产编译失败了,我编译的application.js只包含了

  






我使用的是Rails 3.1.3和ruby-1.9.3-p125。 jQuery使用完全相同的宝石结构,它的工作原理。我做错了什么?



编辑



我也看到了这个问题: Ruby 1.9抛出javascript编码错误。这在这里不适用,我的文件是有效的UTF-8:

  ruby​​-1.9.3-p125:001> d = File.read(./ d3.js)
=>
ruby​​-1.9.3-p125:002> d.encoding
=> #<编码:UTF-8是氢。
ruby​​-1.9.3-p125:003> d.valid_encoding?
=> true

编辑2

我也尝试在我的 config / environment.rb 中插入一些voodoo。它不起作用:

 # -  *  -  encoding:utf-8  -  *  -  
#加载rails应用程序
需要File.expand_path('../ application',__FILE__)

#--------- VOODOO开始在这里----------- ------
Encoding.default_external =编码:: UTF_8
Encoding.default_internal =编码:: UTF_8
#--------- END VOODO ---- ----------------------

#初始化rails应用程序
Ratecode :: Application.initialize!


解决方案

WEBrick服务器或其他的错误?是否耙资产:预编译工作? (不要忘记在清除资产后)

如果后者失败,请仔细检查$ LANG环境变量的值是否为UTF-8(使用 ENV )。如果rake任务有效,但应用程序失败,那么它可能是服务器环境变量。


I'm trying to create a gem that wraps d3.js, Source can be found at https://github.com/iblue/d3-rails

So when I include this gem in my Gemfile

gem "d3-rails", :git => "git://github.com/iblue/d3-rails.git"

And when I include the javascript in my application.js:

//=require d3

Then my asset compilation fails and my compiled application.js just contains

throw Error("Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT")

I am using Rails 3.1.3 and ruby-1.9.3-p125. jQuery uses exactly the same gem structure and it works. What am I doing wrong?

EDIT:

I also saw this question: Ruby 1.9 throwing javascript encoding error. This does not apply here, my file is valid 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 

EDIT 2:

I also tried to insert some voodoo in my config/environment.rb. It does not work:

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

解决方案

Is the error from a WEBrick server or something else? Does rake assets:precompile work? (don't forget to clear the assets after)

If the latter fails, double check the value of your $LANG environment variables is UTF-8 (with env). If the rake task works but the app is failing then it could be the server env vars.

这篇关于资产流水线编码问题(UTF-8与ASCII-8BIT)与外部宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆