不兼容的字符编码:在rails中使用javascript时,ASCII-8BIT和UTF-8 [英] Incompatible character encodings: ASCII-8BIT and UTF-8 while using javascript in rails

查看:368
本文介绍了不兼容的字符编码:在rails中使用javascript时,ASCII-8BIT和UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的rails 3应用程序,版本1.9.3中使用javascript。当我包括此行%= javascript_include_tag应用程序%> 时出现以下错误:

 产品中的Encoding :: CompatibilityError#index 

不兼容的字符编码:ASCII-8BIT和UTF-8

提取的源代码:

6:<%= javascript_include_tag'jquery-1.7.2.min.js','jquery-ui-1.8.21.custom.min.js'%>
7:<%= stylesheet_link_tag'jquery-ui-1.8.21.custom.css'%>
8:<%= stylesheet_link_tagpro%>
9:<%= javascript_include_tagapplication%>
10:<%= csrf_meta_tags%>
11:< / head>


解决方案

Ruby 1.9在字符串编码方面真的很挑剔。



您必须确保您在整个应用程序和数据库中使用utf8编码文件。



在这种情况下,我将看看application.js,看它是否编码在utf8中,如果它在utf8中包含任何misencoded字符。



也可以尝试在application.rb中设置:

  class Application< Rails :: Application 
config.encoding =utf-8
#您的配置...


end

这在environment.rb之前的initliaze!调用:

  Encoding.default_external = Encoding :: UTF_8 
Encoding.default_internal = Encoding :: UTF_8



我在升级Rails 2时遇到了类似的问题,这对我有帮助。


I am trying to use javascript in my rails 3 app, version 1.9.3. When I include this line %= javascript_include_tag "application" %> I get the following error:

Encoding::CompatibilityError in Products#index 

incompatible character encodings: ASCII-8BIT and UTF-8

Extracted source (around line #9):

6:<%= javascript_include_tag 'jquery-1.7.2.min.js','jquery-ui-1.8.21.custom.min.js' %>
7:<%= stylesheet_link_tag 'jquery-ui-1.8.21.custom.css' %>
8:<%= stylesheet_link_tag  "pro" %>
9:<%= javascript_include_tag "application" %>
10:<%= csrf_meta_tags %>
11:   </head>

解决方案

Ruby 1.9 is really picky when it comes to string encoding.

You have to make sure you're using utf8 encoded files throughout your application and your database.

In this case, I'd look at "application.js" to see if it is encoded in utf8 and if it contains any 'misencoded' characters in utf8.

You can also try to set this in application.rb :

class Application < Rails::Application
  config.encoding = "utf-8"
  #Your conf ...


end

And this in environment.rb before the initliaze! call:

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

I had similar problems while upgrading a Rails 2 and this helped me.

这篇关于不兼容的字符编码:在rails中使用javascript时,ASCII-8BIT和UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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