问题描述
我的问题类似于其他一些问题,但仍然没有为我的情况提供答案。我在我的应用程序的Gemfile中包含jquery gem: / p>
gem'jquery-rails'
在application.js中:
// =需要jquery
// =要求jquery-ui
// =要求jquery_ujs
...
// = require_tree。
我的development.rb包含
#不压缩资产
config.assets.compress = false
#展开加载资产的行
config.assets.debug = true
我的资产没有预编译,没有公共/资产。
本地一切都运行良好。但是当我推送到heroku时,我在页面上获得了不同的application.js文件。它不是一个清单文件,而是缩小了jQuery的版本。所以我得到了两次jQuery。以下是我的页面源代码的样子:
< script src =/ assets / jquery.js?body = 1 type =text / javascript>< / script>
< script src =/ assets / jquery-ui.js?body = 1type =text / javascript>< / script>
< script src =/ assets / jquery_ujs.js?body = 1type =text / javascript>< / script>
...
< script src =/ assets / application.js?body = 1type =text / javascript>< / script>
当我点击 /assets/application.js?body=1
我看到缩小的jQuery。当我在本地运行我的应用程序并单击 /assets/application.js?body=1
时,我只能看到清单。
我尝试添加到development.rb中。
$ p $ config.serve_static_assets = false
没有帮助。我也清理了资产和缓存多次。
我唯一能做的就是设置
$ $ $ codeonfig.assets.debug = false
code>
但是我想知道是否有任何其他选项不会影响调试。
我删除了这一行
// = require_tree。
并在javascripts中创建一个子文件夹,然后将javascript目录中的所有js文件移动到该子文件夹, strong> application.js
并写下此行
// = require_tree ./sub_folder_name
这是一个非常棒的工作。
请注意一件重要的事情:
这可能对您造成影响,因为您包含同一个文件两次通过 javascript_include_tag 和其他application.js手动执行。首先确认,如果是这种情况,您必须包括一次。
My question is similar to some other questions here which still didn't provide an answer for my situation
I am including jQuery gem in my app in Gemfile:
gem 'jquery-rails'
And in application.js:
//= require jquery
//= require jquery-ui
//= require jquery_ujs
...
//= require_tree .
My development.rb has
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
My assets are not precompiled, there is no public/assets.Everything is running great locally. But when I push to heroku I get different application.js file included on the page. Instead of being a manifest file it has minified version of jQuery. Therefore I get jQuery included twice. Here is how source of my page looks like:
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-ui.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
...
<script src="/assets/application.js?body=1" type="text/javascript"></script>
And when I click on /assets/application.js?body=1
I see minified jQuery. When I run my app locally and click on /assets/application.js?body=1
I just see the manifest.I tried to add to development.rb
config.serve_static_assets = false
It didn't help. I also cleared assets and cache multiple times.The only thing that works for me is setting
config.assets.debug = false
But I would like to know if there is any other option that won't affect debugging.
I removed this line
//= require_tree .
and creating a sub folder in javascripts and then moved all js files in javascript directory to that subfolder except application.js
and wrote this line
//= require_tree ./sub_folder_name
It's awsome and working.
One Important thing to Note:
This may cause to you as you are including a same file twice one manually by javascript_include_tag and other by application.js. First confirm that if this is the case you have to include it once.
这篇关于Heroku的Rails应用程序中包含两次jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!