[英]Rails 5 - JS not working in production environment (only)
我在挣扎。
我在我的app / assets / javascripts文件夹中有一系列js文件的rails 5 app。 这些文件中的js在开发环境中运行得很好,但是当我在heroku上发布时,它停止工作。
我可以从chrome检查器看到,从网络选项卡中可见的application.js文件显示了我的应用程序中js文件的内容。 那js似乎并没有在生产中做任何事情。 chrome控制台inpsector中没有出现控制台错误。
我可以从这篇文章中看到,有一系列的事情要尝试。 我已经尝试了所有这些。 我甚至创建了一个全新的应用程序,并一次添加js文件,看看是否有一个引爆点,其中某些东西需要以不同的顺序与其他东西(主要是猜测) - 但这没有解决问题。
我从这篇文章中可以看出一个建议是:
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
然后尝试:
rake assets:clean assets:precompile
我已经尝试了这些建议,仍然无法找到问题。
如果我编写js的方式出错,我希望在我的开发和生产环境控制台检查器中都能暴露出来。 在任一环境中都没有显示错误。
如果生产环境读取js文件时出现问题,我很困惑为什么我可以在网络选项卡中打开的文件中搜索js文件中使用的单词,并查看正确的文本。
我该如何解决这个问题?
我的相关文件是:
应用程序/资产/ JavaScript的/ application.js中
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery-fileupload/vendor/jquery.ui.widget
//= require jquery-fileupload/jquery.iframe-transport
//= require jquery-fileupload/jquery.fileupload
//= require bootstrap-sprockets
//= require moment
//= require bootstrap-datetimepicker
//= require pickers
// require underscore
// require gmaps/google
//= require markerclusterer
//= require cocoon
//= require cable
//= require_tree .
配置/初始化/ assets.rb
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path
# Rails.application.config.assets.paths << Emoji.images_path
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
配置/ production.rb
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
在生产环境中不起作用的相关文件保存在app / assets / javscripts / stance / commercial.js中(因此应在application.js中通过// = require_tree进行标识。
那个文件有:
jQuery(document).ready(function() {
jQuery('[name="organisation[commercial_attributes][standard_financial_split]"]').on('click', function() {
if (jQuery(this).val() == 'true' ) {
jQuery('#commercial_standard_financial_split_content').removeClass('hidden');
} else {
jQuery('#commercial_standard_financial_split_content').removeClass('hidden').addClass('hidden');
}
});
});
任何人都可以帮助一个让js在生产环境中工作的过程吗?
我没有尝试的事情的建议,这不是教程,代码学校(我是代码学校的学生,铁路,udemy和有一百万本书)的东西,但找不到从哪个参考点开始解决这个问题。
对我来说,解决方案是从我的application.html.erb的标题中删除javascript include标记到正文下方。 这解决了我在我的问题中引用的js文件的问题。
但是,这已经破坏了我的谷歌地图javascript,所以我不确定这实际上是一个很好的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.