[英]Rails 4 - .js files not running in production environment - Heroku
I'm having trouble loading my .js files in production on Heroku. 我无法在Heroku上的生产环境中加载.js文件。
I know the files are being picked up from the asset pipeline as they are working in development just fine but I am unable to get the .js working in production. 我知道文件正在从资产管道中拾取,因为它们在开发中工作得很好,但是我无法让.js在生产中工作。
I have created /assets/javascripts/notification.js
containing: 我创建了/assets/javascripts/notification.js
其中包含:
$(document).ready(function() {
$("span").click(function() {
$(".notice").delay(200).fadeOut(2000, function() {
});
});
});
My /assets/javascripts/application.js
file contains: 我的/assets/javascripts/application.js
文件包含:
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
in development, this works great. 在开发中,这很好。
When I deploy to Heroku, I can see that the code is displayed within a single application.js
file, except the document ready function is stripped out, see below production .js file: 当我部署到Heroku时,可以看到代码显示在单个application.js
文件中,除了去除了文档准备功能之外,请参见生产.js文件:
<script src="/assets/application-b9a733c3cc0929ae852e45a6c3a2a5f6.js" data-turbolinks-track="true"></script>
My config/production.rb
contains: 我的config/production.rb
包含:
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.compile = true
If you install the rails_12factor gem as Heroku Recommends it will automatically run rake assets:precompile
on deploy (through a gem dependency named rails_serve_static_assets ). 如果您以Heroku推荐的方式安装rails_12factor gem ,它将在部署时自动运行rake assets:precompile
(通过名为rails_serve_static_assets的gem依赖项 )。
It may skip this step if it sees a public/assets/manifest.* file or a /public/assets directory, which tells it you've already compiled the assets, and it doesn't need to be done again. 如果看到public / assets / manifest。*文件或/ public / assets目录,它可能会跳过此步骤,表明您已经编译了资产,并且无需再次进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.