我一直在将一个项目转换为使用资产管道,但在部署的某个环节遇到了问题。在将资产预编译之前,开发模式下一切正常,但在将其部署到生产服务器时出现以下错误:
simile-ajax-api.js isn't precompiled
项目结构类似于:
|-app/
|-assets/
|-javascripts/
|- application.js
|-vendor/
|-assets/
|-javascripts/
|-timeline/
|-timeline_ajax/
|-simile-ajax-api.js
在我的application.rb文件中,我添加了以下行:
config.assets.paths << "vendor/assets/timeline/timeline_ajax"
在我的production.rb文件中,我添加了以下内容:
precompile_list = %w(app lib vendor).map do |path|
Dir[Rails.root.join(*%W(#{path} assets ** *))].select do |f|
f =~ /(\.js|\.s?css)/
end
end.flatten.map do |f|
f.split(File::SEPARATOR).last
end.uniq
config.assets.precompile = (config.assets.precompile + precompile_list).uniq
config.assets.precompile << Rails.root.join(*%w( vendor assets timeline timeline_ajax simile-ajax-api.js ))
应用程序的javascript文件看起来像这样:
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require global
//= require_tree ../../../vendor/assets/timeline/timeline_ajax/.
//= require_tree ../../../vendor/assets/timeline/timeline_js/.
//= require timeline-api
//= require jquery.dataTables.min
//= require FixedHeader.min
//= require ColVis.min
//= require jquery.ba-resize.min
//= require jquery-ui
//= require jquery.blockUI
//= require jquery-ui-timepicker-addon
//= require autocomplete-rails
//= require_tree ../../../vendor/assets/javascripts/.
//= require_tree .
最后,它被加载到application.html.haml中的部分。
%html
%head
- page_title = @page_title ? "#{@page_title}" : ''
%title= strip_tags page_title
:javascript
Timeline_ajax_url= "#{asset_path('simile-ajax-api.js')}";
Timeline_urlPrefix= '/assets/';
Timeline_parameters='bundle=true'
有任何想法我做错了什么吗?如果需要更多细节,请告诉我。
javascripts
。 - Amar