【发布时间】:2017-09-13 04:24:08
【问题描述】:
我正在尝试在我的 Rails 应用程序中使用这个插件: https://github.com/pguso/jquery-plugin-circliful
我完全按照说明进行了设置,在 application.html.erb 中使用以下内容:
<link href="css/jquery.circliful.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="js/jquery.circliful.min.js"></script>
我认为以下几点:
<div class="row">
<div class="col-md-12">
<div id="your-circle"></div>
</div>
</div>
<script>
$( document ).ready(function() {
$("#your-circle").circliful({
animationStep: 5,
foregroundBorderWidth: 5,
backgroundBorderWidth: 15,
percent: 75
});
});
</script>
在 javascript 控制台中,我看到以下 404 错误:
GET http://localhost:3000/contestants/js/jquery.circliful.min.js
GET http://localhost:3000/contestants/css/jquery.circliful.css
GET http://localhost:3000/contestants/js/jquery.circliful.min.js 404 (Not Found)
Uncaught TypeError: $(...).circliful is not a function
at HTMLDocument.<anonymous> (12:168)
at i (jquery-1.12.4.min.js:2)
at Object.fireWith [as resolveWith] (jquery-1.12.4.min.js:2)
at Function.ready (jquery-1.12.4.min.js:2)
at HTMLDocument.K
由于我正在从文档中复制和粘贴,因此我不确定可能出了什么问题。任何帮助表示赞赏。
【问题讨论】:
-
尝试将这些 CDN 添加到 application.html.erb 中的应用程序脚本标记之前,并将您的 document.ready 称为 $(document).on('turbolinks:load', function() {.. .}
-
参见ruby-on-rails-4-how-to-include-javascript-files-in-rails-web-application,它在rails 中的工作方式略有不同,并且自述文件中的sn-p 不起作用。作为一个快速修复,您可以将脚本放在 public/ 目录中并使用
src='./jquery.circliful.min.js'引用它
标签: jquery html ruby-on-rails ruby circliful