Rails Assets在生产模式下预编译错误

时间:2018-10-05 09:56:11

标签: ruby-on-rails

当我运行rake asset:prcompile RAILS_ENV = production时,我遇到了错误。但是,如果我以开发模式运行,它将运行正常。

assert(beginning.topDisk() < destination.topDisk());

环境

Rails 5.0.7 Ruby 2.4.1

有人可以解决这个问题吗

1 个答案:

答案 0 :(得分:2)

解决了这个问题。在我的application.js文件中有以下代码

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

根据 require_tree 的功能,它将以递归方式包含当前路径的所有js文件。请参阅链接https://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives

In JavaScript files, Sprockets directives begin with //=. In the above case, the file is using the require and the require_tree directives. The require directive is used to tell Sprockets the files you wish to require. Here, you are requiring the files rails-ujs.js and turbolinks.js that are available somewhere in the search path for Sprockets. You need not supply the extensions explicitly. Sprockets assumes you are requiring a .js file when done from within a .js file.

The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory into the output. These paths must be specified relative to the manifest file. You can also use the require_directory directive which includes all JavaScript files only in the directory specified, without recursion.

在我的应用程序中,在两个js文件夹中声明了Gruntfile.js文件。因此,当我进行预编译时,由于该文件在两个js中声明,因此尝试压缩该文件时会抛出错误