我应该首先提到我没有预编译。Ruby on Rails HTML中包含的JS文件的副本
我有8个不同的.js文件(7,不计的application.js),当我使用<%= javascript_include_tag 'application' %>
它打印出:
<script src="/assets/admin.js?body=1" type="text/javascript"></script>
<script src="/assets/brand.js?body=1" type="text/javascript"></script>
<script src="/assets/category.js?body=1" type="text/javascript"></script>
<script src="/assets/home.js?body=1" type="text/javascript"></script>
<script src="/assets/product.js?body=1" type="text/javascript"></script>
<script src="/assets/setting.js?body=1" type="text/javascript"></script>
<script src="/assets/user.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
正因为如此,一些我的jQuery(使用切换)不工作因为他们正在执行多次。
我该如何才能简单地使用application.js?
我的application.js文件:
// 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
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require jquery.ui.all
//= require_tree .
你的'application.js'文件是什么样的? '应用。js'实际上应该是包含所有其他文件的清单。也许我错过了一些东西,并没有完全理解你的问题。哪些文件被复制? – theIV
所有Js文件都合并到application.js中,这意味着它们不再需要在HTML中进行链接。因为它们是,代码被复制到独立的JS文件和application.js文件中。我用我的application.js清单更新了我的问题 –