10
我想从application.js中创建一个自定义清单javascript文件。我从application.js中获取代码并将其粘贴到一个新文件中,该文件称为“other_manifest.js”,并放置在assets/javascrips目录中。下面是代码:Rails资产管道:如何创建自定义清单文件
// 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
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .
在我assets.rb文件,我已经包含行:
Rails.application.config.assets.precompile += %w(other_manifest.js)
我预编译和局部清理资产,然后当我运行该页面,所有我得到的是清单文件中的确切文本。它没有引入任何文件。我如何创建自定义清单文件?
你在app/views/layouts/application.html文件中替换了'application.js'吗? – itsnikolay
我放入一个if/else,这取决于页面,application.js显示或other_manifest.js显示 – Philip7899