Plupload插件就是一个很好的例子。这是添加到vendor
目录的插件列表:
./plupload/jquery.plupload.queue
./plupload/jquery.plupload.queue/css
./plupload/jquery.plupload.queue/css/jquery.plupload.queue.css
./plupload/jquery.plupload.queue/img
./plupload/jquery.plupload.queue/img/backgrounds.gif
./plupload/jquery.plupload.queue/img/buttons-disabled.png
./plupload/jquery.plupload.queue/img/buttons.png
./plupload/jquery.plupload.queue/img/delete.gif
./plupload/jquery.plupload.queue/img/done.gif
./plupload/jquery.plupload.queue/img/error.gif
./plupload/jquery.plupload.queue/img/throbber.gif
./plupload/jquery.plupload.queue/img/transp50.png
./plupload/jquery.plupload.queue/jquery.plupload.queue.js
./plupload/jquery.ui.plupload
./plupload/jquery.ui.plupload/css
./plupload/jquery.ui.plupload/css/jquery.ui.plupload.css
./plupload/jquery.ui.plupload/img
./plupload/jquery.ui.plupload/img/plupload-bw.png
./plupload/jquery.ui.plupload/img/plupload.png
./plupload/jquery.ui.plupload/jquery.ui.plupload.js
./plupload/plupload.browserplus.js
./plupload/plupload.flash.js
./plupload/plupload.flash.swf
./plupload/plupload.full.js
./plupload/plupload.gears.js
./plupload/plupload.html4.js
./plupload/plupload.html5.js
./plupload/plupload.js
./plupload/plupload.silverlight.js
./plupload/plupload.silverlight.xap
不要将这些文件重新定位到各种样式表,javascripts和images目录中,最好将它们留在原位并使用Sprockets require指令引用它们。这是如何完成的,特别是对于图像文件和其他资产,如.swf和.xap?
答案 0 :(得分:4)
您可以使用Sprockets provide
directive。
例如,这就是我使用Plupload的方式:
# app/assets/javascripts/plupload.js
//= require plupload/plupload
//= require plupload/plupload.flash
//= require plupload/plupload.silverlight
//= provide plupload/dependencies
相应的供应商目录的组织方式如下:
vendor
├── assets
│ ├── javascripts
│ │ └── plupload
│ │ ├── dependencies
│ │ │ ├── plupload.flash.swf
│ │ │ └── plupload.silverlight.xap
│ │ ├── plupload.flash.js
│ │ ├── plupload.js
│ │ └── plupload.silverlight.js
│ └── stylesheets
└── plugins
当我想使用Plupload时,我使用<%= javascript_include_tag 'plupload' %>
,并使用asset_path
帮助程序填充Plupload配置:
<%= javascript_include_tag 'plupload' %>
<script type="text/javascript">
$(function() {
var uploader = new plupload.Uploader({
runtimes : 'flash,silverlight',
multipart : true,
multipart_params : {
'authenticity_token' : '<%= form_authenticity_token %>'
},
flash_swf_url :
'<%= asset_path "plupload/dependencies/plupload.flash.swf" %>',
silverlight_xap_url :
'<%= asset_path "plupload/dependencies/plupload.silverlight.xap" %>',
url : '<%= url_for [@item, :photos] %>',
// ...
});
希望有所帮助。
答案 1 :(得分:2)
我可能错了,但正如Rails文档中提到的那样:
这并不是说资产可以(或应该)不再存在 上市;它们仍然可以并且将作为静态文件提供 应用程序或Web服务器。如果您愿意,您只能使用app / assets 您的文件在提供之前要经过一些预处理。 http://ryanbigg.com/guides/asset_pipeline.html
由于您不希望对这些文件进行任何预处理,可以使用好的旧公用文件夹作为答案吗?