gpt4 book ai didi

javascript - HTML 中包含的 JS 文件的 Ruby on Rails 副本

转载 作者:行者123 更新时间:2023-11-29 19:53:58 24 4
gpt4 key购买 nike

我应该首先提到我没有预编译。

我有 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(使用 Toggles)无法工作,因为它们被执行了多次。

如何让它简单地使用 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 .

最佳答案

除了删除 //= require_tree . 正如 Mike 所说。尝试以下命令:

$ rake tmp:clear tmp:create assets:clean

这将清除您的临时文件和缓存的 Assets 文件。

此外,如果您只是想要单个 application.js 而不是 7 个 .js 包含脚本标签。设置以下选项 config/environments/development.rb

# Expands the lines which load the assets
config.assets.debug = false

希望对你有帮助

关于javascript - HTML 中包含的 JS 文件的 Ruby on Rails 副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16611250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com