【问题标题】:Adding JavaScript to Rails将 JavaScript 添加到 Rails
【发布时间】:2014-04-14 21:52:38
【问题描述】:

我是 Ruby 的新手,正在做我的第一个项目。这是我正在使用的版本...

  • 红宝石 2.1.1p76
  • Rails 4.1.0

我在添加 JavaScript 文件时遇到问题。我正在关注this article(特别是Site-wide Scripts部分)阅读文章后,我将jquery.js & jquery.validate.min.js保存在vendor/assets/javascripts下和我自己的脚本app/assets/javascripts/additionalJS目录下的accRefConfig.js

这就是我的 app/assets/javascripts/application.js 清单的样子(没有删除 cmets,希望没关系):

  // This is a manifest file that'll be compiled into application.js, which will include all the files listed below.
  // 
  // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
  // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
  // 
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the compiled file.
  // 
  // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details about supported directives.
  // 
  // = require jquery
  // = require jquery.validate.min
  // = require_tree ./additionalJS

还有我的应用程序布局...

   <head>
      <title>Hello World</title>
      <%= stylesheet_link_tag "application.css", media: "all", "data-turbolinks-track" => true %>
      <%= javascript_include_tag "application" %>
  </head>

但这给了我以下错误....

我做错了什么?提前感谢您的时间和帮助:)

顺便说一句,我也试过&lt;%= javascript_include_tag "application.js" %&gt;,但同样的错误信息

【问题讨论】:

标签: javascript ruby-on-rails ruby asset-pipeline ruby-on-rails-4.1


【解决方案1】:

看到抛出的错误说 .../jquery.js 的 UTF-8 字节序列无效。

尝试将文件重新保存为 UTF-8。

【讨论】:

  • 感谢您的回复。我现在无法访问我的虚拟机,当我有机会尝试时会通知你:)
  • 非常感谢您,它成功了!!!我猜你确实每天都在学习新东西 :) 老实说,从来不知道这么简单的事情会很重要。万一外面有人不像我这样:P,这就是我所做的:redhotwords.com/unicode.html
猜你喜欢
  • 1970-01-01
  • 2020-08-02
  • 2015-10-27
  • 2013-01-08
  • 1970-01-01
  • 1970-01-01
  • 2016-03-10
  • 1970-01-01
  • 2017-01-18
相关资源
最近更新 更多