使用Rails预编译其他资产

时间:2013-01-03 16:23:17

标签: ruby-on-rails ruby ruby-on-rails-3.2 asset-pipeline

我一直在转换一个项目来使用资产管道,但是我正在使用部署的一部分。在将帽子部署到生产服务器之后,我收到了以下错误。 (在没有预编译资产的情况下,一切都在开发模式下正常工作)

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 ))

application.js看起来像这样:

// 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'

任何想法我都会出错?如果您需要更多详细信息,请与我们联系。

1 个答案:

答案 0 :(得分:1)

我认为没有必要说出这样的路径:

//= require_tree ../../../vendor/assets/timeline/timeline_ajax/.

只是:

//= require_tree timeline/timeline_ajax/.

因为所有资产(无论位于何处)都以同样的方式查找。简单地说 - 如果目录名为assets,则管道会查找要包含的文件。

编辑:看起来您的vendor目录结构有点奇怪:通常您将.js文件直接复制到assets/javascripts目录。我认为包括assets/vendor/timeline会让事情变得复杂。只需将timeline目录复制到vendor/assets/javascripts