我應該首先提到我沒有預編譯。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清單更新了我的問題 –