编程语言
首页 > 编程语言> > Ruby on Rails3.2中javascript文件中的Sprockets :: EncodingError

Ruby on Rails3.2中javascript文件中的Sprockets :: EncodingError

作者:互联网

我有一个Ruby On Rails(Ruby 1.9; Rails 3.2.13)应用程序.我正在尝试使用Highcharts创建图表.但是我在Product#index中的Sprockets :: EncodingError上在浏览器上遇到错误
sample / app / assets / javascripts / highcharts.js的UTF-8字节序列无效.代码文件如下.我在assets / javascript文件夹中添加了文件rails.js,highcharts.js和jquery1.4.2.min.js.

application.html.erb

  <!DOCTYPE html>
  <html>
    <head>
     <title>Sample</title>
      <%= stylesheet_link_tag    "application", :media => "all" %>
      <%= javascript_include_tag "jquery-1.4.2.min", "rails", "highcharts" %>
      <%= csrf_meta_tags %>
     </head>
    <body>

 <%= yield %>
 </body>
</html>

index.html.erb文件如下.

 <script type ="text/javascript" charset="UTF-8">
  </script>
  $(function() {
   new Highcharts.Chart({
    chart:{
     renderTo:"products_chart" 
     type: 'column'
    }

   title: {
    text: 'Number of Patents Granted',   
   },

 credits: {
  position: {
  align: 'left',
  x: 20
  },
      href: 'http://www.uspto.gov',
  text: 'Source: U.S. Patent & Trademark Office'
  },

 xAxis: {
  categories: [
   '2001', '2002', '2003', '2004', '2005',
   '2006', '2007', '2008', '2009', '2010',
   '2011' ]
   },

 yAxis: {
    title: {
   text: 'No. of Patents'
    }
 },

 plotOptions: {
 },
   series: [{
    name: 'UK',
    data: [ 4351, 4190, 4028, 3895, 3553,4323, 4029, 3834, 4009, 5038, 4924 ]
    }]

   });
});

谁能帮助解决此错误?

谢谢

解决方法:

转到“使用编码保存”菜单,然后选择“ UTF-8”.

在Sublime Text 2中,这在File>使用编码保存> UTF-8.

标签:ruby-on-rails-3-2,highcharts,javascript,ruby-on-rails
来源: https://codeday.me/bug/20191123/2066106.html