[英]Rails in production: JavaScript files not run
I try to run rails application (Rails 4.2.0) in production mode with these settings: 我尝试使用以下设置在生产模式下运行Rails应用程序(Rails 4.2.0):
config/environment/production.rb config / environment / production.rb
require 'uglifier'
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.assets.js_compressor = Uglifier.new(output: {ascii_only: true, quote_keys: true})
config.serve_static_files = true
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
config.log_level = :debug
config.i18n.fallbacks = true
end
config/initializer/assets.rb config / initializer / assets.rb
Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.precompile += %w( ckeditor/* admin.*)
app/assets/application.js app / assets / application.js
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require ckeditor/init
//= require select2
//= require init/select2
//= require lib/jquery.mCustomScrollbar.min
//= require lib/moment.min
//= require lib/daterangepicker
//= require init/daterangepicker
//= require lib/bootstrap-notify
//= require underscore
//= require gmaps/google
// lightgallery:
//= require lib/lightgallery/picturefill.min.js
//= require lib/lightgallery/lightgallery
//= require lib/jquery.mousewheel.min.js
//= require jquery.sortable
//= require photos
//= require_tree ./admin
//= require_tree .
app/assets/photos.js app / assets / photos.js
// Loading photo for resources
(function($) {
conslole.log('It is photos.js')
// Check File API support
if(window.File && window.FileList && window.FileReader){
var filesInput = document.getElementById('upload_photos');
//...
}
}());
I expect to see in browser console message 'It is photos.js', but it's absent. 我希望在浏览器控制台消息中看到“这是photos.js”,但该消息不存在。
I explored compiled file 我浏览了编译文件
http://localhost:3000/assets/admin-a0144eae675b202d7e9a9fbca944636e6aa24fe7b0140b44ec68928303bc4717.js http:// localhost:3000 / assets / admin-a0144eae675b202d7e9a9fbca944636e6aa24fe7b0140b44ec68928303bc4717.js
and found this piece of code in browser sources: 并在浏览器源代码中找到了这段代码:
(function($) {
console.log('It is photos.js')
// Check File API support
if(window.File && window.FileList && window.FileReader){
var filesInput = document.getElementById('upload_photos');
//...
}
}());
I can't understand why no message is shown in console. 我不明白为什么控制台中没有显示任何消息。
But a lot of other js files and libs are working correct. 但是许多其他js文件和库也可以正常工作。
Try rake assets:precompile
in your app directory then push the new compiled files in production. 在您的应用目录中尝试
rake assets:precompile
,然后将新的编译文件推送到生产环境中。 I ran into the same problem with asset files not loading properly in production and this command did the trick for me. 我遇到了同样的问题,资产文件无法在生产中正确加载,此命令为我解决了问题。
Hope it helps ;) 希望能帮助到你 ;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.